





























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






























Uses of exception handling
Process exceptions from program components
Handle exceptions in a uniform manner in large
projects
Remove error-handling code from “main line” of
execution
What if Exception is not handled?
Might terminate program execution
Two Types
Checked
Must be caught or declared in a throws clause
Compile will issue an error if not handled appropriately
Subclasses of Exception other than subclasses of RuntimeException.
Other arrive from external factors, and cannot be solved by debugging
Communication from an external resource – e.g. a file server or database
Throwable
Exception Error
IOException
ArrayIndexOutOfBoundsException InputMismatchException
NullPointerException
Runtime Exception
AWTError ThreadDeath
ClassCastException
OutOf MemoryError
ArithmeticException
Checked Exceptions
UnChecked Exceptions Error
Basic Java exception handling is managed via keywords: try ,
catch, finally, throw, throws.
To manually throw an exception, use the keyword throw.
throws exception out of the method, requiring it to be caught and handled by an appropriate exception handler
Any exception that is thrown out of a method must be specified as such by a throws clause.
Example: Unchecked Exceptions
public class UcException {
public static void main(String args[ ]) {
System.out.println(args[0]);
}
}
Example: Unchecked Exceptions
public class UcException {
public static void main(String args[ ]) {
System.out.println(args[0]);
}
}
Example: Unchecked Exceptions
Modification
public class UcException {
public static void main(String args[ ]) {
try {
System.out.println(args[0]);
}catch (IndexOutOfBoundsException ex) {
System.out.println(“You forget to pass command line argument”);
Example: Checked Exceptions
compile & execute