Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to know possible exceptions when using try catch?

According to MSDN, it is a bad practice to catch exceptions without a specific type and using for example System.Net.Exception

Do I have to dig into the msdn manual to see the possible exception types each time I'm going to catch an error. Or is there any way in the IDE to let me see this quickly.

Currently I'm using Visual Studio 2013 Express Edition

 try
 {
    using (WebClient goog = new WebClient()) 
    {
       goog.DownloadString("http://google.com");
    } 
 }
 catch(Exception E)
 {
    saveLog("methodname", E.Message);
 }

EDIT : In this link, it looks like VS already has an option to display exeptions, however, when I'm selecting a method, it only shows the type, and the parameters of the method. But it doesn't show exceptions

like image 702
Rafik Bari Avatar asked Sep 29 '22 22:09

Rafik Bari


1 Answers

The best practice is, generally, to only add handling for exceptions you expect to occur during the run-time of your program.

If you're dealing with files, for example, handling the ***NotFoundException types makes sense. Proper coding will ensure things like ArgumentNullException don't happen, so that doesn't need handling, etc.

like image 91
Tom Lint Avatar answered Oct 08 '22 11:10

Tom Lint