下面程序抛出了一个“异常”并捕捉它。请在横线处填入适当内容完成程序。( )classTrowsDemo{public staticvoidprocedure() IllegalAccessExcepton{ System.out.println(“insideprocedure”); throw new IllegalAccessException(“demo”);}}
A: try
B: catch
C: throw
D: throws
A: try
B: catch
C: throw
D: throws
举一反三
- (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(); } } }
- 抛出异常,使用关键字( ) A: try B: throw C: throws D: catch
- 在下列程序的下划线处,填入适当语句使程序能正确执行并输出异常栈信息。 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():"); 【 】;}}}
- 哪一个关键字用于手动抛出异常? A: try B: catch C: throw D: throws
- 如要抛出异常,应该使用下列( )子句。 A: catch B: throw C: try D: throws