I have a couple of user defined exception classes and I want to have a handler for all of those exception classes that I write. For example, in my business logic, I catch one of those user defined exceptions and in the catch block, I instantiate my handler which takes the reference for the exception as the argument along with a String message...sothing like below,
And in the handler class, I need to throw a new object of type e, something like below,
The Handler constructor,
My goal is to say
throw new UserException(); in the Handler constructor and this UserException() part will be dynamic. Any suggestions on how to implement it?
Originally posted by Norm Radder: your goal to "throw new UserException()" Since you've got the Class object for the class e.getClass() can you use reflection to create a new instance of UserException and then throw that?
Not sure why you'd want to do that instead of just doing "new UserException()"
It may be of any type...today it is UserException(), tomorrow it is UserException1() and so on...so I generically want to throw the Object that comes in. I tried e.getClass() and then how can I create a new object using reflection? Can you please let me know!