程序 A
method B()A 中call B(),
B()中如果catch到Exception,
让程序A就此停止,后面的不再执行。在B()catch 到Exception 后,执行System.exit(0) 即可吗?System.exit(0)在java 中用得多么?什么情况下用?有什么坏的影响没有?谢谢
method B()A 中call B(),
B()中如果catch到Exception,
让程序A就此停止,后面的不再执行。在B()catch 到Exception 后,执行System.exit(0) 即可吗?System.exit(0)在java 中用得多么?什么情况下用?有什么坏的影响没有?谢谢
如果你只是想程序停止运行,执行一个 return 就可以了
System.exit(0)用的挺多的,尤其是在GUI编程里面。
这个语句和return还是差挺多的,return是返回调用它的控制程序或控制台。
而System.exit(0)就直接退出JVM了。
public class EE { /**
* @param args
*/
void aa(){
String str =null;
try{
int i= str.length();
*System.out.println("after ===== ");
}catch(Exception e ){
System.out.println("aa Exception "+e.toString());
System.exit(0) ;
//return;
}finally{
System.out.println("aa finally...");
}
} void dd(){
System.out.println("before try aa");
aa();
**System.out.println("after try aa"); }
public static void main(String[] args) {
// TODO Auto-generated method stub
new EE().dd();
}}
1)如果用return,跳过*,直接回到**,继续执行.
2)如果用System.exit(0) ,程序就此停住。
3)如果用System.exit(1) 呢,一样。
能让该程序停止执行,并且对其他正在同一系统运行的程序毫无影响。这样可以吗?不过如果不判断是正确还是错误之退出,0和1无所谓把
退去当前JVM进程,其他进程不受影响。--同一系统运行的程序毫无影响
这里的同一系统是指的同一个操作系统中的吧,如果是就不影响的。
System.exit(0) 很多都是用在SWING等图形界面编程中,点退出,就把程序关闭了