Skip to main content
9 events
when toggle format what by license comment
Sep 14, 2012 at 6:36 comment added lorddev It might be more helpful with examples like "OutOfMemory" or "NullReference" or what not. But this here is the right answer. The code analysis rule title is poorly worded. But the best-practice is to try to handle the kind of exceptions you will get, with a certain understanding of what they would be, assuming you wrote the code or have access to documentation, and then have a general exception catch. A real-world example would be in the olden days when performing a server-side Response.Redirect() in an ASP.NET page would result in ThreadAbortExceptions, which were quite unnecessary.
Sep 9, 2012 at 16:21 history edited Rotem CC BY-SA 3.0
added 16 characters in body
Sep 9, 2012 at 16:21 comment added Rotem @all You're totally right, I see now all my answer does is prove the opposite point. Edited.
Sep 9, 2012 at 16:20 comment added Victor Hurdugaci If you catch a general exception only to log it, then you should rethrow it after logging.
Sep 9, 2012 at 16:16 comment added pdr Contrived or not, it makes your answer wrong. As soon as you start catching exceptions like Out Of Memory and Disk Full and just swallowing them, you're proving why catching general exceptions is in fact bad.
Sep 9, 2012 at 16:14 comment added Bob Horn @Rotem I think you have a good answer here. But pdr has a point. The code, as is, makes it look like catching and continuing is fine. Some beginner, seeing this example, might think that's a good approach.
Sep 9, 2012 at 15:48 comment added Rotem @pdr Surely you realize it's a contrived example. The point was to demostrate catching of both specific and general exceptions, not how to handle them.
Sep 9, 2012 at 15:43 comment added pdr Wait. Why would you ever want to log an unknown exception to console and carry on? If it's an exception that you didn't even know could be thrown by the code, you're probably talking about a system failure. Carrying on in this scenario is probably a really bad idea.
Sep 9, 2012 at 15:24 history answered Rotem CC BY-SA 3.0