Why is try {…} finally {…} good; try {…} catch{} bad?

I have seen people say that it is bad form to use catch with no arguments, especially if that catch doesn’t do anything: StreamReader reader=new StreamReader(“myfile.txt”); try { int i = 5 / 0; } catch // No args, so it will catch any exception {} reader.Close(); However, this is considered good form: StreamReader reader=new … Read more

Why are empty catch blocks a bad idea? [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago. Improve this question I’ve just seen a question on try-catch, which people (including Jon Skeet) say empty catch blocks … Read more

How using try catch for exception handling is best practice

while maintaining my colleague’s code from even someone who claims to be a senior developer, I often see the following code: try { //do something } catch { //Do nothing } or sometimes they write logging information to log files like following try catch block try { //do some work } catch(Exception exception) { WriteException2LogFile(exception); … Read more

How do you implement a re-try-catch?

Try-catch is meant to help in the exception handling. This means somehow that it will help our system to be more robust: try to recover from an unexpected event. We suspect something might happen when executing and instruction (sending a message), so it gets enclosed in the try. If that something nearly unexpected happens, we … Read more

Will code in a Finally statement fire if I return a value in a Try block?

I’m reviewing some code for a friend and say that he was using a return statement inside of a try-finally block. Does the code in the Finally section still fire even though the rest of the try block doesn’t? Example: public bool someMethod() { try { return true; throw new Exception(“test”); // doesn’t seem to … Read more

Do try/catch blocks hurt performance when exceptions are not thrown?

During a code review with a Microsoft employee we came across a large section of code inside a try{} block. She and an IT representative suggested this can have effects on performance of the code. In fact, they suggested most of the code should be outside of try/catch blocks, and that only important sections should … Read more