第七章 例外处理(新)美化后.pptVIP

  • 1
  • 0
  • 约1.22万字
  • 约 34页
  • 2019-11-27 发布于湖北
  • 举报
用户自定义异常类格式为: 例如: class 自定义异常类名 extends Exception { 异常类体; } class MyException extends Exception { … } 自定义异常类格式 用户定义的异常同样要用try-catch捕获,但必须由用户自己抛出异常。 例如: throw new MyException( ) 自定义异常类说明 class Exception_exp{ public static void main(String[] args){ try { System.out.println(2+3=+add(2,3)); System.out.println(-8+10=+add(-8,10));} catch (Exception e) { System.out.println(Exception is +e);} } static int add(int n,int m) throws UserException { if (n0|| m0) throw new UserException(); return n+m;

文档评论(0)

1亿VIP精品文档

相关文档