lx7.java

来自「JAVA学习源代码,大家可以好好参考,请多提宝贵意见」· Java 代码 · 共 64 行

JAVA
64
字号
public class Lx7
{
  static void demoproc()
  { //throw new Exception();
    try
    {
       throw new NullPointerException("demo");
       //System.out.println("not thow!");
    }
    
    catch(NullPointerException e)
    {
     System.out.println("Caught inside demoproc."+e);
     throw e;
    } 
    //throw new Exception();
   }
   public static void throwException() throws Exception{
   
   //try语句块产生一个异常
      try {
     System.out.println( "\n***Calling method throwException***\n" );
     throw new Exception();
     //throw new NullPointerException("demo");
         }

   //打印异常信息,并重新抛出异常
     catch ( Exception e ){
     	//catch(NullPointerException e){
     System.out.println(
               "Exception handled in static method throwException"+e );
     System.out.println("Rethrow the exception object " 
                                                                      + "in static method throwException");
     throw e;
    }
 }
   
   public static void main(String args[])
   {
    try
    {
    	throwException();
      //demoproc();
    }
    catch( Exception exception ){
     System.out.println("Exception handled in static method doesNotThrowException" );
     System.out.println("Does not Rethrow the exception object " 
                                                                     + "in static method doesNotThrowException");
   }
    try
    {
    	demoproc();
    }
    catch(NullPointerException e){System.out.println("Recaught:"+e);}
    
    //catch(Exception e){ System.out.println("already caught Exception!!"); }
   /* catch(NullPointerException e)
    {
     System.out.println("Recaught:"+e.toString());
    }*/
    
   } 
    }    

⌨️ 快捷键说明

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