public static void main(String[] args){ new Test().f(); } }
【在 w*******s 的大作中提到】 : return before finally?
Z*Z
6 楼
awesome, let me verify a little. thanx!
【在 g**e 的大作中提到】 : System.exit : runtime error : when a daemon thread is abandomed
Z*Z
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
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
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
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 ...
【在 g*****g 的大作中提到】 : When a thread is interrupted. : : hopi
g*g
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
13 楼
you mean, like this? still not working ... public class Test extends Thread{
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
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
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
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
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! : : ,