Click here to Skip to main content
15,916,042 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionDistribution problem, System.IO.FileNotFoundException Pin
jamesrgoodwin8-Sep-07 2:53
jamesrgoodwin8-Sep-07 2:53 
AnswerRe: Distribution problem, System.IO.FileNotFoundException Pin
Scott Dorman8-Sep-07 2:56
professionalScott Dorman8-Sep-07 2:56 
Questiondtpicker problem Pin
d_smit7-Sep-07 18:56
d_smit7-Sep-07 18:56 
AnswerRe: dtpicker problem Pin
rohitsrivastava9-Sep-07 20:30
rohitsrivastava9-Sep-07 20:30 
QuestionException Error .NET COM DLL on mapped NETWORK drive Pin
ankwrk7-Sep-07 5:30
ankwrk7-Sep-07 5:30 
AnswerRe: Exception Error .NET COM DLL on mapped NETWORK drive Pin
Dave Kreskowiak7-Sep-07 8:44
mveDave Kreskowiak7-Sep-07 8:44 
QuestionException handling Pin
dreamz64807-Sep-07 3:38
dreamz64807-Sep-07 3:38 
AnswerRe: Exception handling Pin
Scott Dorman7-Sep-07 4:30
professionalScott Dorman7-Sep-07 4:30 
First, please put large code snippets like this inside of <pre> tags to keep the formatting and help make it more readable.
try
{
   MethodthatraisesException();
}
catch (ExceptionA e1)
{
   LogMessage(e1);
}
catch (ExceptionB e1)
{
   LogMessage(e1);
}
 
try
{
   MethodthatraisesException();
}
catch (ExceptionA e1)
{
   LogMessage(e1);
}
There are some differences in runtime behavior between these. In the second example, you will only catch exceptions of type ExceptionA and anything derived from it. So, if ExceptionB is derived from ExceptionA this will work, if not you'll only catch one of the exceptions.

That being said, in your examples, you are "eating" the error. You catch the exception, log it, but don't pass it up the chain by calling throw(); to rethrow the exception. This may be what you want, but generally you should only catch an exception if you can do some meaningful cleanup work as a result; if not, let the exception bubble up to whoever is interested.

There really aren't any differences in performance between the two. The runtime still has to perform a stack walk all the way up the chain looking for something that will handle the exception.




Scott.

—In just two days, tomorrow will be yesterday.

[Forum Guidelines] [Articles] [Blog]

GeneralRe: Exception handling Pin
Urs Enzler9-Sep-07 22:01
Urs Enzler9-Sep-07 22:01 
GeneralRe: Exception handling Pin
Scott Dorman10-Sep-07 3:05
professionalScott Dorman10-Sep-07 3:05 
QuestionGenerating text in a JPG Pin
JoeRip6-Sep-07 19:21
JoeRip6-Sep-07 19:21 
AnswerRe: Generating text in a JPG Pin
Michael Potter7-Sep-07 4:55
Michael Potter7-Sep-07 4:55 
GeneralRe: Generating text in a JPG Pin
JoeRip7-Sep-07 10:26
JoeRip7-Sep-07 10:26 
GeneralRe: Generating text in a JPG Pin
Michael Potter7-Sep-07 10:37
Michael Potter7-Sep-07 10:37 
GeneralRe: Generating text in a JPG Pin
JoeRip7-Sep-07 11:23
JoeRip7-Sep-07 11:23 
GeneralRe: Generating text in a JPG Pin
Michael Potter7-Sep-07 11:33
Michael Potter7-Sep-07 11:33 
GeneralRe: Generating text in a JPG Pin
Luc Pattyn7-Sep-07 12:26
sitebuilderLuc Pattyn7-Sep-07 12:26 
GeneralRe: Generating text in a JPG Pin
Ed.Poore9-Sep-07 11:17
Ed.Poore9-Sep-07 11:17 
QuestionVisual Studio.NET IDE Pin
yogesh_kumar_agarwal5-Sep-07 19:22
yogesh_kumar_agarwal5-Sep-07 19:22 
AnswerRe: Visual Studio.NET IDE Pin
Ed.Poore9-Sep-07 11:18
Ed.Poore9-Sep-07 11:18 
QuestionFramework origins Pin
HakunaMatada5-Sep-07 18:30
HakunaMatada5-Sep-07 18:30 
AnswerRe: Framework origins Pin
originSH5-Sep-07 21:57
originSH5-Sep-07 21:57 
AnswerRe: Framework origins Pin
Scott Dorman6-Sep-07 18:26
professionalScott Dorman6-Sep-07 18:26 
Question2.0 Printer manipulation Pin
SBarnettAZ5-Sep-07 13:37
SBarnettAZ5-Sep-07 13:37 
QuestionRemoting. I Just Don't Get It Pin
#realJSOP5-Sep-07 9:21
professional#realJSOP5-Sep-07 9:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.