Java示例异常方法


Java示例异常方法

public class NewClass {

   public static void main(String[] args) {

      try {

         throw new Exception("My Exception");

      } catch (Exception e) {

         System.err.println("Caught Exception");

         System.err.println("getMessage():" + e.getMessage());

         System.err.println("getLocalizedMessage():" + e.getLocalizedMessage());

         System.err.println("toString():" + e);

         System.err.println("printStackTrace():");

         e.printStackTrace();

      }

   }

}