Recommendation 62: Avoid nesting exceptions
Exceptions should be allowed to upload on the call stack, do not use catch too much, and then throw. Excessive use of catch brings two problems:
1) More code. It looks as if you don't know how to deal with exceptions, so you always catch them all the time.
2) hides the stack information so that you don't know where the exception really happened.
Nesting without reason is what we should try to avoid. Of course. If you really need to catch this exception to restore some state and then re-throw it, the code should look like this:
Try { //... } catch (Exception) { // work code Throw ; }
Or:
Try { //... } catch { // Work code Throw ; }
Try to avoid throwing exceptions like this:
Catch (Exception ex) { // Throw ex; }
A direct throw ex instead of a throw resets the stack information.
Turn from: 157 recommendations for writing high-quality code to improve C # programs Minjia
157 recommendations for writing high-quality code to improve C # programs--Recommendation 62: Avoid nesting exceptions