Z*****Z 发帖数: 723 | 1 for a try/catch/finally block when is the finally block not executed? |
w*******s 发帖数: 940 | 2 return before finally?
【在 Z*****Z 的大作中提到】 : for a try/catch/finally block when is the finally block not executed?
|
g**e 发帖数: 6127 | 3 System.exit
runtime error
when a daemon thread is abandomed
【在 Z*****Z 的大作中提到】 : for a try/catch/finally block when is the finally block not executed?
|
g**e 发帖数: 6127 | 4 no
【在 w*******s 的大作中提到】 : return before finally?
|
Z*****Z 发帖数: 723 | 5 not working
public class Test {
void f(){
try{
System.out.println("in a try block");
return ;
} finally{
System.out.println("finally");
}
}
public static void main(String[] args){
new Test().f();
}
}
【在 w*******s 的大作中提到】 : return before finally?
|
Z*****Z 发帖数: 723 | 6 awesome, let me verify a little.
thanx!
【在 g**e 的大作中提到】 : System.exit : runtime error : when a daemon thread is abandomed
|
Z*****Z 发帖数: 723 | 7 System.exit daemon thread are correct
the second reason seems not correct
public class Test {
void f(){
try{
System.out.println("in a try block");
//throw new Error("error"); // not working
throw new RuntimeException(); // not working
} finally{
System.out.println("finally");
}
}
public static void main(Str
【在 g**e 的大作中提到】 : System.exit : runtime error : when a daemon thread is abandomed
|
g**e 发帖数: 6127 | 8 i shouldn't say "run time error". i actually mean the thread or jvm got
killed or crashed in try/catch block.
finally block will be executed definitely in your code below.
【在 Z*****Z 的大作中提到】 : System.exit daemon thread are correct : the second reason seems not correct : public class Test { : : void f(){ : try{ : System.out.println("in a try block"); : //throw new Error("error"); // not working : throw new RuntimeException(); // not working : } finally{
|
Z*****Z 发帖数: 723 | 9 Yep, i know the RuntimeException one will definitely be executed. I was hopi
ng throwing an Error will make a change, which apparently not ...
【在 g**e 的大作中提到】 : i shouldn't say "run time error". i actually mean the thread or jvm got : killed or crashed in try/catch block. : finally block will be executed definitely in your code below.
|
g*****g 发帖数: 34805 | 10 When a thread is interrupted.
hopi
【在 Z*****Z 的大作中提到】 : Yep, i know the RuntimeException one will definitely be executed. I was hopi : ng throwing an Error will make a change, which apparently not ...
|
|
|
Z*****Z 发帖数: 723 | 11 i dont think so
public class Test extends Thread{
@Override
public void run(){
try{
while(true){
System.out.println("in a try block");
Thread.sleep(500);
}
} catch (InterruptedException e) {
e.printStackTrace();
} finally{
System.out.println("finally");
【在 g*****g 的大作中提到】 : When a thread is interrupted. : : hopi
|
g*****g 发帖数: 34805 | 12 When you don't catch InterruptedException of course.
【在 Z*****Z 的大作中提到】 : i dont think so : public class Test extends Thread{ : : @Override : public void run(){ : try{ : while(true){ : System.out.println("in a try block"); : Thread.sleep(500); : }
|
Z*****Z 发帖数: 723 | 13 you mean, like this? still not working ...
public class Test extends Thread{
@Override
public void run(){
try {
f();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
void f() throws InterruptedException{
try{
while(true){
System.out.println("in a try block");
【在 g*****g 的大作中提到】 : When you don't catch InterruptedException of course.
|
s***8 发帖数: 1136 | 14 when machine crashes, or the process is killed.
Q: for a try/catch/finally block when is the finally block not executed?
A: when machine crashes, or the process is killed. A finally is a finally,
very simple, period. What do you think? |
Z*****Z 发帖数: 723 | 15 i think u r cool. but i dont want to be too cool to my interviewer.
,
【在 s***8 的大作中提到】 : when machine crashes, or the process is killed. : Q: for a try/catch/finally block when is the finally block not executed? : A: when machine crashes, or the process is killed. A finally is a finally, : very simple, period. What do you think?
|
m******t 发帖数: 2416 | 16 That's right! It also happened last time when I tripped the wire, and also
the weekend before that, when the earth was hit by that damn meteor!
,
【在 s***8 的大作中提到】 : when machine crashes, or the process is killed. : Q: for a try/catch/finally block when is the finally block not executed? : A: when machine crashes, or the process is killed. A finally is a finally, : very simple, period. What do you think?
|
g**e 发帖数: 6127 | 17 haha
【在 m******t 的大作中提到】 : That's right! It also happened last time when I tripped the wire, and also : the weekend before that, when the earth was hit by that damn meteor! : : ,
|