Exception Handling
Exception Handling
• Exceptions
– Indicate problems that occur during a
program’s execution
– Occur infrequently
• Exception handling
– Can resolve exceptions
• Allow a program to continue executing or
• Notify the user of the problem and
• Terminate the program in a controlled manner
– Makes programs robust and fault-tolerant
3
• Programs can
– Recover from exceptions
– Hide exceptions
– Pass exceptions up the “chain of command”
– Ignore certain exceptions and let someone else
handle them
• An exception is a class
• Usually derived from one of the system’s exception
base classes
• If an exceptional or error situation occurs,
program throws an object of that class
• Object crawls up the call stack
10
11
13
14
15
16
19
20
23
24
27
28
32
34
35
38
40
41