Mr_Fulano
asked on
Question regarding Try, Catch, Finally
I have some C# code in VS2010 that I've been working on. The code contains a Try, Catch, Finally block. When I test my code using the  Console.Writeline() method, I can see Exception error messages in the Output window, which can obviously be turned off if I don't want to display the exception messages.
So, my question is this...are those error messages the messages that are generated from my Catch block or are those exception error message in addition to the ones being trapped in my Catch block?
My concern is that the Try, Catch, Finally block is not trapping all the exceptions. If that were the case, would the application abort or would it just display error messages in the Output window?
I hope this question is not too confusing, but I'm a bit puzzled myself.
Thanks for your help,
Fulano
So, my question is this...are those error messages the messages that are generated from my Catch block or are those exception error message in addition to the ones being trapped in my Catch block?
My concern is that the Try, Catch, Finally block is not trapping all the exceptions. If that were the case, would the application abort or would it just display error messages in the Output window?
I hope this question is not too confusing, but I'm a bit puzzled myself.
Thanks for your help,
Fulano
>>from my Catch block or are those exception error message in addition to the ones being trapped in my Catch block?
They come from your WriteLine statement, in other words they come from where you code them to come from.
They come from your WriteLine statement, in other words they come from where you code them to come from.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@kaufmed - good point, they never crossed my mind.
ASKER
All the responses were fantastic. -- I was able to get a complete solution to my question from both athar13 and from Kaufmed, who both did a great job of explaining the Try/Catch statement, and the "first chance" exceptions .... my exception messages are ALL "first chance" exceptions. (Please see below)
-- A first chance exception of type 'System.NullReferenceExcep tion' occurred in MetaDatareader_with_Loop.e xe
-- A first chance exception of type 'System.Reflection.TargetI nvocationE xception' occurred in mscorlib.dll
Per the link provided by Kaufmed, I now know the following:
"...For applications / components which handle exceptions gracefully, first chance exception messages let the developer know that an exceptional situation was encountered and was handled.'
From athar13's post, I now know that I can catch multiple exceptions, which I never knew!!! Very useful indeed.
Thank you both and I have split the points.
Fulano
-- A first chance exception of type 'System.NullReferenceExcep
-- A first chance exception of type 'System.Reflection.TargetI
Per the link provided by Kaufmed, I now know the following:
"...For applications / components which handle exceptions gracefully, first chance exception messages let the developer know that an exceptional situation was encountered and was handled.'
From athar13's post, I now know that I can catch multiple exceptions, which I never knew!!! Very useful indeed.
Thank you both and I have split the points.
Fulano
ASKER
Excellent!!!!
to capture all the exceptions, you can try:
Open in new window
try-catch (C# Reference)
https://msdn.microsoft.com/en-sg/library/0yd65esw.aspx
try-catch-finally (C# Reference)
https://msdn.microsoft.com/en-us/library/dszsf989.aspx