这个程序中的错误是什么? [英] Whats the error in this program?
本文介绍了这个程序中的错误是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class exprop{
void method3(){
int result = 100 / 0; //Exception Gere
}
void method2(){
method3();
}
void method1(){
method2();
}
public static void main(String args[])
try{
exprop obj=new exprop();
obj.method1();
System.out.println("Continue with Normal Flow...");
}
catch(Exception e){
System.out.println("Exception is handled here");
}
}
我尝试过: <我不能在main方法中执行try catch块吗?
What I have tried:
can't we execute a try catch block inside a main method?
推荐答案
嗯...也许你在main
方法中使用了一个大括号块?
Well... perhaps if you used a curly bracket block inside yourmain
method?
public static void main(String args[]){
try{
exprop obj=new exprop();
obj.method1();
System.out.println("Continue with Normal Flow...");
}
catch(Exception e){
System.out.println("Exception is handled here");
}
}
这篇关于这个程序中的错误是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文