I am currently using two catch blocks after a try block. The first catches SqlExceptions, the second Exceptions.
If the SqlException does not have a specific message, I want it to be handled by the general catch block. Is there any way I can pass the exception from the first catch block to the second, or do I have to duplicate the code?
I am currently using two catch blocks after a try block. The first catches
Share
First of all you should ask yourself if you really want to catch
Exception. If you cannot handle the exception, you shouldn’t catch it.If you do want to catch the all purpose exception and share some kind of processing between your catch blocks duplicating code is not the right approach imo. Why not encapsulate the processing in a method and call that from both blocks?