由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 1 quick interview question
相关主题
请教一个简单的问题这几个函数可以用Generic之类的东西合并么?
@Override annotation.what's wrong with this simple applet? (转载)
为啥画不出来?如何关闭打开的输入输出?
倒霉的Swing代码总是导致Exception, fatal errorstatic final的问题
how to access the overrided fields of the parent?Java Regular Expression Question
泛型问题override/overload/overwrite in Java
问个题EJB2 Question
求教一个Java问题 IllegalMonitorStateExceptionreturn null or empty list/set/...
相关话题的讨论汇总
话题: finally话题: try话题: test话题: block话题: public
进入Java版参与讨论
1 (共1页)
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 ...

相关主题
泛型问题这几个函数可以用Generic之类的东西合并么?
问个题what's wrong with this simple applet? (转载)
求教一个Java问题 IllegalMonitorStateException如何关闭打开的输入输出?
进入Java版参与讨论
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!
:
: ,

1 (共1页)
进入Java版参与讨论
相关主题
return null or empty list/set/...how to access the overrided fields of the parent?
请教 class cast problem泛型问题
what is your opinion in this case?问个题
对 spring 的 exception 处理方式真是不适应求教一个Java问题 IllegalMonitorStateException
请教一个简单的问题这几个函数可以用Generic之类的东西合并么?
@Override annotation.what's wrong with this simple applet? (转载)
为啥画不出来?如何关闭打开的输入输出?
倒霉的Swing代码总是导致Exception, fatal errorstatic final的问题
相关话题的讨论汇总
话题: finally话题: try话题: test话题: block话题: public