Professional Documents
Culture Documents
Exceptions
Ziyati Houssaine
Java
1
Exceptions
While running software many things can go wrong. You have to deal with
errors or exceptional behavior.
On this slide exception means the Java term and error a nonspecified
general term.
2
Hierarchy
Object
Throwable
Error Exception
... RuntimeException
3
Checked Exceptions
4
Unchecked Exceptions
5
Introduction
6
Try and Catch
7
Stack Trace
The stack trace shows the order of method calls leading to point where
the exception occurs.
8
Stack Trace
1 Division by zero .
2 java . lang . A r i t h m e ti c E x c e p t i o n : / by zero
3 at Calc . main ( Calc . java :6)
4 at sun . reflect . N a t i v e M e t h o d A c c e s s o r I m p l . invoke0 ( Native Method )
5 at sun . reflect . N a t i v e M e t h o d A c c e s s o r I m p l . invoke (
N a t i v e M e t h o d A c c e s s o r I m p l . java :62)
6 at sun . reflect . D e l e g a t i n g M e t h o d A c c e s s o r I m p l . invoke (
D e l e g a t i n g M e t h o d A c c e s s o r I m p l . java :43)
7 at java . lang . reflect . Method . invoke ( Method . java :498)
8 at com . intellij . rt . execution . application . AppMain . main ( AppMain . java
:147)
9
Finally
10
Propagate Exceptions
11
Propagate Exceptions - Test 1
12
Propagate Exceptions - Test 2
13
Java API
1 https://docs.oracle.com/javase/7/docs/api/
14
Creating new Exceptions
15
Creating new Exceptions - Test
16