Professional Documents
Culture Documents
Exception Handling
Exception?
• Short hand for Exceptional Event
• NullPointerException
• ArrayIndexOutOfBoundsException
Throwing an Exception
1. Information about the
error
2. Type of the error
3. State of the program when
error occurred
Java Runtime
Environment
(JRE)
Java Runtime
Environment
(JRE)
Exception
Searching the call stack for the
object exception handler
What Exception Handler does then?
Exception
Handler
Types of Exceptions
• Checked Exceptions
• Unchecked Exceptions
Error vs Exception
• Error: An Error indicates serious problem that
a reasonable application should not try to
catch.
}
catch(ExceptionName en) {
}
Exception Handling – Multiple Catch
• try-catch
Syntax:
try {
}
catch(ExceptionName1 en) {
}
catch(ExceptionNameN en) {
}
Exception Handling - finally
• try-catch-finally
Syntax:
try {
}
catch(ExceptionName en) {
}
finally {