Generally, the correct way is to use try-catch-finally or try-finally:
If you are doing something in the error log or doing something else. Catch can also be used to execute your code, but not for good practice. You cannot do anything about the error if you want, therefore it is finally used.
Finally, it is used when it is important to execute a piece of code, regardless of whether an error is selected or not. For example, in C ++ or another language, when you work with files inside, the file is closed (you cannot open it). Look here for some examples.
source share