您的位置:首页 > 编程语言 > Java开发

java中异常(Exception)的定义,意义和用法。举例

2014-08-26 15:02 351 查看
我们先给出一个例子,看看异常有什么用?

例:1.1

public class Test {

public static void main(String[] args) {

int userInput=0;

int I = 6 / userInput;

System.out.println("马克-to-win:优雅结束");

}

}
输出结果:
Exception in thread "main" java.lang.ArithmeticException: / by zero

at Test.main(Test.java:4)

例:1.1.2
public class Test {

public static void main(String[] args) {

try

{

int userInput=0;

int I = 6 / userInput;

}

catch(Exception e)

{

System.out.println(e);

。。。。。。。。。。。。。。。。。

详情请进:http://www.mark-to-win.com/JavaBeginner/JavaBeginner5_web.html#PointDefinitionUsageException
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐