Java Tutorial/Apache Common/ExceptionUtils

Материал из Java эксперт
Перейти к: навигация, поиск

ExceptionUtils.getThrowableCount

   <source lang="java">

import org.apache.rumons.lang.exception.ExceptionUtils; import org.apache.rumons.lang.exception.NestableException; public class MainClass {

   public static void main(String[] args) {
       try {
           a();
       } catch (Exception e) {
           System.out.println(
               "Number of Throwable objects in the exception chain is: " +
               ExceptionUtils.getThrowableCount(e));
           e.printStackTrace();
       }
   }
   public static void a() throws Exception {
       try {
           b();
       } catch (Exception e) {
           throw new ApplicationException("Packaged into Nestable", e);
       }
   }
   public static void b() throws Exception {
       throw new Exception("The Root Exception");
   }

} class ApplicationException extends NestableException {

   public ApplicationException(String msg, Throwable cause) {
       super(msg, cause);
   }

}</source>