I'm still restructuring the code I have been given to update on my current work project, and I've come to the point where I'm looking at how the code handles an 'exceptional' input, that doesn't conform to the business logic.
In essence, the code stitches together various different excel spreadsheets, tarts them up and lets the user 'download' them to their workspace for later analysis.
This is what I have set in the code:
If the code ends up (anywhere) trying to, for instance, import an empty spreadsheet into the final work book (something that should never happen, under the business logic) then write out to a LinkedList variable (ErrorList) in a static class (MyVariables) like so, the error:
MyVariables.ErrorList.add("My Specific Error Text");
Then I throw an exception like so:
throw new PICNICException();
Then in the frame that called the trail of methods, the exception is finally caught and I can write, something like this:
JOption.showMessageDialog(This, MyVariables.ErrorList.getLast(), "Title Relevant to what Code is Doing", JOption.ERROR_DIALOG)
have feel I have to do this as, I have no way to pop up the Message Dialog (which is the desired behaviour on erroring) from within the method that's thrown this exception. Without completely refactoring the entire code base, and making a singleton that can be accessed anywhere to handle these message dialogues, I don't see any other way of doing this.
I can't help but feel this is a gigantic hack, and there is a better method for doing this.
Am I handling my exceptions in the best possible manner, given my situation? What would the best practice be?