我用eclipse写了一段程序,但eclipse给我了一段警告:finally block does not complete normallytry {
// try 块里主要是写读文件,当遇到一些错误时,设置isError标志位,并抛出异常 } catch (EOFException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
dis.close();
is.close();
alermSchedule.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if ( isError || !fileExists ) {
return null;
} else {
return timeVector;
}
}
}
但我如果要是写成以下形式,就没有警告,try {
} catch (EOFException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
dis.close();
is.close();
alermSchedule.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if ( isError || !fileExists ) {
return null;
} else {
return timeVector;
}我主要想知道这个警告是如何产生的?为什么出会出现这样的警告?
谢谢大家了。
// try 块里主要是写读文件,当遇到一些错误时,设置isError标志位,并抛出异常 } catch (EOFException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
dis.close();
is.close();
alermSchedule.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if ( isError || !fileExists ) {
return null;
} else {
return timeVector;
}
}
}
但我如果要是写成以下形式,就没有警告,try {
} catch (EOFException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
dis.close();
is.close();
alermSchedule.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if ( isError || !fileExists ) {
return null;
} else {
return timeVector;
}我主要想知道这个警告是如何产生的?为什么出会出现这样的警告?
谢谢大家了。
Do not return from finally directly.