Tag: int on () off for false final Dex string index
package is common;
public class TestException {
Public TestException () {
}
Boolean testEx () throws Exception {
boolean ret = true;
try {
ret = testEx1 ();
} catch (Exception e) {
E.printstacktrace ();
System.out.println ("testEx, catch Exception");
ret = false;
Throw e;
} finally {
System.out.println ("testEx, finally; return value= "+ ret);
return ret;
}
}
Boolean testEx1 () throws Exception {
boolean ret = true;
try {
ret = TESTEX2 ();
if (!ret) {
return false;
}
System.out.println ("testEx1, at the end of Try");
return ret;
} catch (Exception e) {
E.printstacktrace ();
System.out.println ("testEx1, catch Exception");
ret = false;
Throw e;
} finally {
System.out.println ("testEx1, finally; return value= "+ ret);
return ret;
}
}
Boolean testEx2 () throws Exception {
boolean ret = true;
try {
int B = 12;
int C;
for (int i = 2; I >=-2; i--) {
c = b/i;
System.out.println ("i=" + i);
}
return true;
} catch (Exception e) {
E.printstacktrace ();
System.out.println ("testEx2, catch Exception");
ret = false;
An important throw can replace return if the back side finally is return and the method will not receive an abnormal
(That is, the exception thrown by the result of the catch is covered by the return in the finally). If there is no return, there is no exception to be thrown, and the exception that will be thrown will be received.
Throw e;
} finally {
System.out.println ("testEx2, finally; return value= "+ ret);
return ret;
throw new ArrayIndexOutOfBoundsException ();
}
System.out.println ("In-line");
return false;
}
public static void Main (string[] args) {
TestException testException1 = new TestException ();
try {
Testexception1.testex ();
} catch (Exception e) {
E.printstacktrace ();
System.out.println ("main");
}
}
}
Results
i=2
I=1
Java.lang.ArithmeticException:/By zero
At an abnormal. Testexception.testex2 (testexception.java:48)
At an abnormal. Testexception.testex1 (TESTEXCEPTION.JAVA:25)
At an abnormal. Testexception.testex (TESTEXCEPTION.JAVA:10)
At an abnormal. Testexception.main (testexception.java:71)
TESTEX2, catch exception
TESTEX2, finally; Return Value=false
Java.lang.ArrayIndexOutOfBoundsException
At an abnormal. Testexception.testex2 (testexception.java:62)
At an abnormal. Testexception.testex1 (TESTEXCEPTION.JAVA:25)
At an abnormal. Testexception.testex (TESTEXCEPTION.JAVA:10)
At an abnormal. Testexception.main (testexception.java:71)
TESTEX1, catch exception
TESTEX1, finally; Return Value=false
TestEx, finally; Return Value=false
Material http://www.cnblogs.com/to-creat/p/5688235.html
Java exceptions throw throw and return