public
class
ExceptionTest {
public
ExceptionTest() {
}
boolean
testEx()
throws
Exception {
boolean
ret =
true
;
try
{
ret = testEx1();
}
catch
(Exception e) {
System.out.println(
"testEx, catch exception"
);
ret =
false
;
throw
e;
}
finally
{
System.out.println(
"testEx, finally; return value="
+ ret);
return
ret;
}
}
boolean
testEx1(){
boolean
ret =
true
;
try
{
ret = testEx2();
if
(!ret){
return
false
;
}
System.out.println(
"testEx1, at the end of try"
);
return
ret;
}
catch
(Exception e) {
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
;
int
b =
12
;
int
c;
for
(
int
i =
2
; i >= -
2
; i--) {
c = b / i;
System.out.println(
"i="
+ i);
}
System.out.printf(
"这句话打打出来了吗??????"
);
return
true
;
}
public
static
void
main(String[] args) {
ExceptionTest testException1 =
new
ExceptionTest();
try
{
testException1.testEx();
}
catch
(Exception e) {
e.printStackTrace();
}
}
}
class
myException
extends
Exception{
public
void
printException(){
System.out.println(
"产生异常!"
);
}
}