public class TestException {
public void test(int i,int j) throws ArithmeticException{
int x=i/j;
}
public static void main(String[] arg0){
TestException te=new TestException();
te.test(9, 0);
}
}这是个测试类,test方法throws了ArithmeticException的异常,为什么在main方法里不用try{}catch(){}编译也能通过,eclipse也不会报说要用try catch包含.
一般情况下方法有throws的话,在调用这个方法时候不是要用try catch包含吗
public void test(int i,int j) throws ArithmeticException{
int x=i/j;
}
public static void main(String[] arg0){
TestException te=new TestException();
te.test(9, 0);
}
}这是个测试类,test方法throws了ArithmeticException的异常,为什么在main方法里不用try{}catch(){}编译也能通过,eclipse也不会报说要用try catch包含.
一般情况下方法有throws的话,在调用这个方法时候不是要用try catch包含吗
解决方案 »
- Collections中的牛X比较器
- 为甚么我编写一个服务器端和客户端的聊天程序,但是只能循环聊天一次!!!求各位大侠帮忙!!!下面是代码!!!
- 音乐播放器的问题 求高手指点!!!不知道咋回事
- 请问有哪位大侠有jpaser的教程?
- 急!!!!!给点一个颜色,如何计算出其色调(色相),饱和度,亮度
- 为什么resultset不能update数据呢?
- odbc直接用 純jdbc輿sql server相連 出了問題了.
- 用Hashtable class怎么定义表上限?
- System.out.println() 和System.err.println()有什么区别?THANKS
- boolean 类型占几个字节的空间?
- 请问:如何按"+"分解字符串"12+365+45+27+68"?
- 怎样在java程序中加密xml文档呢?
extends RuntimeException
当出现异常的运算条件时,抛出此异常。例如,一个整数“除以零”时,抛出此类的一个实例。
-----------------------------------------------------------------------------
以上是 jdk 上的解释
如果,你抛出非 RuntimeException 时,需要 try/catch,比如 throws Exception
继承于Exception,但是不是继承与Runtime(也是继承于Exception)的异常你必须得抓。
继承于Exception,但是不是继承与Runtime(也是继承于Exception)的异常你必须得抓。
RuntimeException 是哪些能够在JVM正常操作中抛出的异常的父类
A method is not required to declare in its throws clause any subclasses of RuntimeException that might be thrown during the execution of the method but not caught.
一个方法不需要去申明抛出任何RuntimeException 类的子类,这些子类也许在这个方法执行期间抛出,但可以不用捕获
都必须得捕捉。