001 package com.mockrunner.base; 002 003 /** 004 * If Mockrunner catches an exception inside application code, 005 * it rethrows it as an instance of this class. 006 */ 007 public class NestedApplicationException extends RuntimeException 008 { 009 private Throwable nested; 010 011 public NestedApplicationException(String message, Throwable nested) 012 { 013 super(message); 014 this.nested = nested; 015 } 016 017 public NestedApplicationException(Throwable nested) 018 { 019 this.nested = nested; 020 } 021 022 /** 023 * Returns the nested exception 024 * (which may also be a <code>NestedApplicationException</code>) 025 * @return the nested exception 026 */ 027 public Throwable getNested() 028 { 029 return nested; 030 } 031 032 /** 033 * Returns the root cause, i.e. the first exception that is 034 * not an instance of <code>NestedApplicationException</code>. 035 * @return the root exception 036 */ 037 public Throwable getRootCause() 038 { 039 if(nested == null) return null; 040 if(!(nested instanceof NestedApplicationException)) return nested; 041 return ((NestedApplicationException)nested).getRootCause(); 042 } 043 }