class MyException extends Exception{ private int detail; MyException( int a ){ detail = a;} public String toString( ){ return "MyException "+detail; } } public class ExceptionDemo{ public static void compute(int a) throws MyException { System.out.println("called compute("+a+")"); if( a<0 ) throw new myexception(a); system.out.println("normal exit"); } public static void main( string args[] ){ try{ compute(0 ); compute(-3 catch( myexception e system.out.println("caught "+e); 执行结果: ___________________>
为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!