Exception handling in C#

  • Thread starter Thread starter s33k3r
  • Start date Start date
S

s33k3r

hi all,

I'll try and be brief, coz in the mood I'm in now if I start ranting
there's no stopping.

Actually I wanted to know if i can do any thing except, print debug
messages in the final catch handler. From all the samples I've seen
everyone seems to throw and rethrow the exceptions ad infinium.

What I'm looking for is something like this

try
{
some operation
}
catch(exception ex)
{
if (ex.errorno == something)
do some damage control
else
throw new exception("i blew up here",ex
}

Is this possible in c# ? From my noob knowhow i expect not but still
can some one confirm ?
Thanks for your time
 
Hi s33k3r,

Actually I wanted to know if i can do any thing except, print debug
messages in the final catch handler. From all the samples I've seen

yes, you can do pretty much anything in a catch block. However, note
that if an exception occurs *in* the catch block, you have an unhandled
exception (unless there is another try..catch around it).

Hope this helps,

Roland
 
Hi Roland,
yes, you can do pretty much anything in a catch block. However, note that
if an exception occurs *in* the catch block, you have an unhandled
exception (unless there is another try..catch around it).

Not exactly,
surely the exceeption can be handled elsewhere.
The newly thrown exception, if not caught inside the catch block simply will
excit the try statement and can be caught in an outer try block or further
up the callstack, but it wan't be handled by a catchblock of the same try
statement.
 
Back
Top