What you are trying to do is infinitely wrong!!! For you have not posted any details, I'll assume you are throwing different exceptions and then do something according to type of the thrown exception.
A better approach is to return a value (maybe an enum
) and do processing according to it's value rather than the type of the thrown exception. There are of course better approaches to the problem, but I cannot say anything speciffic unless you give more details about what you are trying to do.
Eceptions should be used only in exceptional cases because:
- Everybody expects that
- No one would expect your use-case
- Exceptions are slow compared to a
switch
on enum for instance - It's unintuitive and plain wrong
- The people who will maintain your code will hate you :)