class Excep {
public int division( int a, int b ) {
return a / b;
}
}
class ExcepTest {
public static void main( String[] args ) {
Excep except = new Excep();
try {
except.division( 5, 0 );
System.out.println( "exception" );
}
catch( ArithmeticException e ) { //提示"不不兼容的类型",请问怎么改才能使用这个ArithmeticException类 System.out.println( e.toString() );
}
}
----------------解决方案--------------------------------------------------------
....不知道....
----------------解决方案--------------------------------------------------------
异常的类型和你函数的返回类型不匹配,也就是说ArithmeticException异常不是用来捕获除零错误的,其实使用Exception异常就可以。
----------------解决方案--------------------------------------------------------
public class ArithmeticExceptionextends RuntimeException
当出现异常的运算条件时,抛出此异常。例如,一个整数“除以零”时,抛出此类的一个实例。
这是帮助上的解释,应该是用在运算异常上的呀..
----------------解决方案--------------------------------------------------------
建议你多去看看API吧
----------------解决方案--------------------------------------------------------
class Excep {
public int division( int a, int b ) {
return a / b;
}
}
class ExcepTest {
public static void main( String[] args ) {
Excep except = new Excep();
try {
except.division( 5, 0 );
System.out.println( "exception" );
}
catch( ArithmeticException e ) {
System.out.println( e.toString() );
}
}//这里你少了一个 大括号"}"
}
--------------------Configuration: <Default>--------------------
Process completed.
编译没问题啊
----------------解决方案--------------------------------------------------------