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

📄 rethrow.java

📁 程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件
💻 JAVA
字号:
package examples.exceptions;

/** A class to demonstrate rethrowing an exception
  */
public class ReThrow {
   /** A utility class method that always throws
     * an exception
     * @exception IllegalValueException For
     *            demonstration purposes
     */
   public static void methodThrowsException() 
      throws IllegalValueException {
         throw new IllegalValueException( 150 );
   }

   /** A utility class method that catches, alters,
     * and rethrows IllegalValueException exceptions
     * @exception IllegalValueException An uncaught
     *            exception from a called method
     */
   public static void methodReThrowsException() 
         throws IllegalValueException {
      try {
         methodThrowsException();
      }
      catch( IllegalValueException ive ) {
         System.out.println( "Caught illegal value "
                             + ive.getValue() );
         if ( ive.getValue() > 100 ) {
            ive.setValue( ive.getValue() - 100 );
            throw ive;
         }
      }
   }

   /** Test method for the class
     * @param args Not used
     */
   public static void main( String[] args ) {
      try {
         methodReThrowsException();
      }
      catch( IllegalValueException ive ) {
         System.out.println( "Caught illegal value "
                             + ive.getValue() );
      }
   }
}

⌨️ 快捷键说明

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