在下列程序的下划线处,填入适当语句使程序能正确执行并输出异常栈信息。 public class ThrowableException{ public static void main(String args[]{ try{ throw new Throwable(“这里是本人定义的异常”); }catch(Throwable e){ System.out.println("Caught Throwable"); System.out.println("e.getMessage(): "+e.getMessage()); System.out.println("e.toString():"+e.toString()); System.out.println( "e.printStackTrace():"); 【 】;}}}
举一反三
- 中国大学MOOC: 下列代码中构造方法的返回类型是()public class Village { Village () { System .out .println(“hiding in Village”) ; } public static void main( String args [ ]) { Village c =new Village ( ) ;}class Village { public static void main( String args [ ]) { Village c =new Village ( ) ; } Village () { System .out .println(“hiding in Village”) ; } }
- 智慧职教: 下列程序运行后输出的结果是___________。 public class MyException { public static void main (String[] args) { try{ throw new Throwable() ; } catch (Throwable e) { System. out. print (e. getMessage()) ; } } }
- (9-2)下面程序能够通过编译检查。 public class Demo5 { public static void main(String[] args) { try { System.out.println(3/0); System.out.println("你好"); }catch(Exception e) { e.printStackTrace(); }catch(ArithmeticException e) { e.printStackTrace(); } } }
- (9-4)请根据提示补全程序空白处,使程序能够正确运行。 public class Demo { static void show() throws ① { System.out.println("抛出异常!"); throw new IllegalAccessException("一个异常"); } public static void main(String []args) { try { show(); }catch( ② e ) { e.printStackTrace(); } } }
- 请说出下列程序的输出结果_____________,_____________。import java.io.IOException;public class E {public static void main(String args[]){try { methodA();}catch(IOException e){System.out.print("你好");return;}finally {System.out.println("thanks");}}public static void methodA() throws IOException{throw new IOException();}}