Throw an exception positively
1 | void noZero(int i) throws Exception { |
javap1
2
3
4
5
6
7
8
9
10
11
12
13
14void noZero(int) throws java.lang.Exception;
Code:
0: iload_1
1: ifne 14
// class java/lang/Exception
4: new #2
7: dup
// String no zero
8: ldc #3
// Method java/lang/Exception.
//"<init>":(Ljava/lang/String;)V
10: invokespecial #4
13: athrow
14: return
- if not equals pass the throw part
- if equals take constant string as param create a Exception.
- throw it to the caller[handler?].
Catch an exception
1 | void e() { |
javap
1 | void e(); |
excption table
Every catcher have a chance to catch.
astore_1
Beginning of handler for excpSentry() store thrown value in local var 1.
Finally
1 | int f() { |
javap
1 | int f(); |
5/6 copy instructions of 13/14.
7th is the Exception handler.
11th can’t reach.
what’s the object of istore_2/ istore_3 ???
istore_2
the catcher itself’s handler?istore_3
the finaly’s handler comes from istore_2
?
any
mean in range instructions finished then goto target.
The final return handle by finally got 2