CSE205: Object Oriented
Programming
Lecture # 11: Exception Handling
Muhammad Imran
(Based on Java, The Complete Reference)
http://www.secscourses.tk
1
, Outline
• Exception
• Exception Handling Fundamentals
• Exception Types
• Uncaught Exceptions
• Using try and catch
• Multiple catch Clauses
• throw
• throws
• finally
2
, Exception
• An exception is an abnormal condition that arises in a code
sequence at runtime
• An exception is a runtime error
• In OO terms, an exception is an object that describes an exceptional
condition that has occurred in a piece of code
• When an exceptional condition arises, an object representing that
exception is created and thrown in the method that caused the
error
That method may choose to handle the exception itself, or pass it on.
Either way, at some point the exception is caught and processed.
3
, Exception-Handling Fundamentals
• Exceptions can be generated by the Java runtime
system, or they can be manually generated by our
code
Exceptions thrown by Java relate to fundamental errors
that violate the rules of the Java language or the
constraints of the Java execution environment
Manually generated exceptions are typically used to
report some error condition to the caller of a method
4
Programming
Lecture # 11: Exception Handling
Muhammad Imran
(Based on Java, The Complete Reference)
http://www.secscourses.tk
1
, Outline
• Exception
• Exception Handling Fundamentals
• Exception Types
• Uncaught Exceptions
• Using try and catch
• Multiple catch Clauses
• throw
• throws
• finally
2
, Exception
• An exception is an abnormal condition that arises in a code
sequence at runtime
• An exception is a runtime error
• In OO terms, an exception is an object that describes an exceptional
condition that has occurred in a piece of code
• When an exceptional condition arises, an object representing that
exception is created and thrown in the method that caused the
error
That method may choose to handle the exception itself, or pass it on.
Either way, at some point the exception is caught and processed.
3
, Exception-Handling Fundamentals
• Exceptions can be generated by the Java runtime
system, or they can be manually generated by our
code
Exceptions thrown by Java relate to fundamental errors
that violate the rules of the Java language or the
constraints of the Java execution environment
Manually generated exceptions are typically used to
report some error condition to the caller of a method
4