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

📄 usingexceptions.java

📁 金旭亮的java教案
💻 JAVA
字号:
//  UsingExceptions.java
// Demonstration of the try-catch-finally
// exception handling mechanism.
public class UsingExceptions {
   public static void main( String args[] )
   {
      try {
         throwException();
      }
      catch ( Exception e )
      {
         System.err.println( "Exception handled in main" );
      }

      doesNotThrowException();
   }

   public static void throwException() throws Exception
   {
      // Throw an exception and immediately catch it.
      try {
         System.out.println( "Method throwException" );
         throw new Exception();  // generate exception
      }
      catch( Exception e )
      {
         System.err.println(
            "Exception handled in method throwException" );
         throw e;  // rethrow e for further processing

         // any code here would not be reached
      }
      finally {
         System.err.println(
            "Finally executed in throwException" );
      }

      // any code here would not be reached
   }

   public static void doesNotThrowException()
   {
      try {
         System.out.println( "Method doesNotThrowException" );
      }
      catch( Exception e )
      {
         System.err.println( e.toString() );
      }
      finally {
         System.err.println(
            "Finally executed in doesNotThrowException" );
      }

      System.out.println(
         "End of method doesNotThrowException" );
   }
}

⌨️ 快捷键说明

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