有下列程序 在public void test()后加上哪一句可以使编译不出错。()
A: throw MyException
B: throws MyException
C: throw new MyException()
D: throws new MyException()
A: throw MyException
B: throws MyException
C: throw new MyException()
D: throws new MyException()
举一反三
- class MyException extends (1) { } public class Demo { public static void main(String[] args) { try { show(); } catch ( (2) e) { e.printStackTrace(); } } public static void show() (3) MyException { throw new MyException(); } 以上程序,创建了一个自定义异常(编译异常),请补全空白处代码
- 智慧职教: 下列程序运行后输出的结果是___________。 public class MyException { public static void main (String[] args) { try{ throw new Throwable() ; } catch (Throwable e) { System. out. print (e. getMessage()) ; } } }
- Java中,自定义异常代码( )。 A: public class MyException implents Exception{ } B: class MyException extends Throwable{ } C: class MyException { } D: class MyException extends Exception{ }
- 中国大学MOOC:"如下程序的输出是什么____#include #include using namespace std;struct MyException : public exception{ const char * what () const throw () { return "C++ Exception"; }};int main(){ try { throw MyException(); } catch(MyException& e) { std::cout << "MyException" << std::endl; } catch(std::exception& e) { std::cout<<"exception" << std::endl; }}";
- 下面的代码: class E1 extends Exception{ }; class E2 extends E1{ } public class Quiz6_3 { public void f(Boolean flag) throws E1{ //一一X一一 } } 下列的语句,哪—个可以放到--X--位置,而且保证编译成功? A: throw new Exception(); B: throw new E1(); C: throw new E2(); D: throw new Error();