我看教科书上写
try{
//do sth
}catch(Exception e){
//do sth
return -1;
}
return 0;
-----------------------
为什么return 0要写在try-catch外
而不能写在try里?
----------------------
如果我这么写会有什么隐患么?
try{
//do sth
return 0;
}catch(Exception e){
//do sth
return -1;
}
try{
//do sth
}catch(Exception e){
//do sth
return -1;
}
return 0;
-----------------------
为什么return 0要写在try-catch外
而不能写在try里?
----------------------
如果我这么写会有什么隐患么?
try{
//do sth
return 0;
}catch(Exception e){
//do sth
return -1;
}
try{
//do sth1
return 0;
}catch(Exception e){
//do sth2
return -1;
}
}
编译程序必须找到一个绝对可以执行到的return语句
如果你的do sth1和do sth2都有错误的话,不就什么也return不了了