Here is the situation. When I throw an exception, I want my wrapper class to pick it up and put it into a database. (For simplicity I am just printing it in this example).
However, when I throw the exception, the constructor for my exception subclass never gets called.
public class SmartHomeXcp extends Exception { private final StackTraceElement trace[]; private int sizeOfTrace; public SmartHomeXcp(String message) { super(message); trace = getStackTrace(); sizeOfTrace = trace.length; printSize(); } public void printSize() { System.out.println("Size " + sizeOfTrace); for(int i = 0; i < sizeOfTrace; i++) System.out.println("Trace: " + trace[0]); System.out.println("Did we make it here?"); } }
public class ExceptionGiver { public static void causeException() { throw new SmartHomeXcp("Dude exception here!!!!"); } public static void main(String[] args) { ExceptionGiver.causeException(); } }