In the process of writing the program, we are familiar with the Try-catch, catch the exception to deal with, to ensure the robustness of the program.
Today's sudden thought, what if the code in our catch is abnormal? Let's make one of the following assumptions
static void Main (string[] args) { try{ //code A } catch{ //code B } finally{ //code C }}
Following our usual use of code A, we may end up with code B error handling and possibly write the error log at code C.
So the question is, what if we're out of order because of some unpredictable factor in code B or code C? (although I have not encountered this situation, haha)
Then the programmer realizes the following structure with a dead-minded attitude
static void Main (string[] args) { try{ //code A try{ //code B } catch{ //code C } finally{ //code D } //code E } catch{ //code F } finally{ //code G }}
According to this structure, we do not write any code in the position of code F and G (not always an exception?). or write the absolute error-free code, the subject code is in the location of line B, C's location exception handling, D's location to write the log.
So, even if catch and finally are abnormal, they will be caught by the outer catch, so is it absolutely robust?
The absolute robustness of program Try-catch nesting