⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 finallydemo.java

📁 Java学习源代码检索系统免费版
💻 JAVA
字号:
//==============================================================
// FinallyDemo.java - Demonstrate try-catch-finally statements
//
// Java学习源代码检索系统 Ver 1.0 20031015 免费正式版
// 版权所有: 中国IT认证实验室(www.ChinaITLab.com)
// 程序制作: ChinaITLab网校教研中心
// 主页地址: www.ChinaITLab.com    中国IT认证实验室
// 论坛地址: bbs.chinaitlab.com  
// 电子邮件: Java@ChinaITLab.com
//==============================================================

// Exception class
class ThrowMe extends Exception {
 ThrowMe() { }
 ThrowMe(String s) {
  super(s); 
 }
}

class FinallyDemo {
 // Test method -- pass 0, 1, or 2 for different exceptions
 static void testMethod(int n) throws Exception, ThrowMe {
  switch (n) {
  case 1: 
   throw new Exception("Unhandled exception");
  case 2:
   throw new ThrowMe("To the wolves");
  default:
   return;
  }
 }
 // Main program 
 public static void main(String args[]) 
  throws Exception {
  int argument = 0;
  if (args.length > 0)
   argument = Integer.parseInt(args[0]);
  try {
   testMethod(argument);
  } catch (ThrowMe e) {
   System.out.println("ThrowMe: " + e.getMessage());
  } finally {
   System.out.println("Finally statement");
  }
  System.out.println("Statement after try block");
 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -