我怎么知道应该捕获什么样的异常? (视频下载) (全部书籍)马克-to-win:如上例1.1:开始没加try时,程序崩溃,系统打印的是如下的错误,Exception in thread "main" java.lang.ArithmeticException: / by zero at Test.main(Test.java:4),马克-to-win: 所以我们就该捕获ArithmeticException.见下例:1.1.3。
例:1.1.3-本章源码
public class Test {
public static void main(String[] args) {
try
{
int userInput=0;
int I = 6 / userInput;
}
catch(ArithmeticException e)
{
System.out.println(e);
}
。。。。。。。。。。。。。。。。。
详情请进:http://www.mark-to-win.com/index.html?content=JavaBeginner/javaUrl.html&chapter=JavaBeginner/JavaBeginner5_web.html#WhatToCatch