2 ms·
When we wrote C, we often used to use goto statements for error handling. This was a clean pattern because it allowed you to write all the code to handle the cl
by ActorNightly 2y ago
When we wrote C, we often used to use goto statements for error handling. This was a clean pattern because it allowed you to write all the code to handle the cleanup only once. For any error, you would jump to the cleanup code, and at the end of the function, the cleanup code would be executed regardless.
Exceptions in modern languages are essentially that with a more hierarchal structure, because they will auto propagate up the chain, into the exception clause that can go to cleanup code (or in the finally clause)
This is where exception handling is best used for, which requires a minimal number of try statements in critical pieces of the program (if you are handling exceptions from functions and continuing as normal, you are better off using returned error codes)