Yes, that works and preserves the exception. Thanks. I've been searching
MSDN for a list of exceptions (especially PK violation) any ideas on where I
can find a good list? Intellisence has some, but not the ones I'm looking
for.
protected void dv_PR_ItemInser ted(object sender,
DetailsViewInse rtedEventArgs e)
{
if (e.Exception != null)
{
try
{
throw e.Exception;
}
catch (SystemExceptio n ex)
{
lbl_Errors.Text = ex.Message.ToSt ring();
}
catch (Exception ex)
{
lbl_Errors.Text = ex.Message.ToSt ring();
}
finally
{
e.ExceptionHand led = true;
}
}
else
{
Response.Redire ct("~/PR/PR_Item.aspx?PR =" + tb_tPR.Text);
}
}
}
"Leon Mayne" <le**@rmvme.mvp s.orgwrote in message
news:D7******** *************** ***********@mic rosoft.com...
"randy.buchholz " <ra************ @dads.state.tx. uswrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
>>I am trying to capture event exceptions using try/catch.
I can get all exceptions with:
protected void dv_PR_ItemInser ted(object sender,
DetailsViewIns ertedEventArgs e)
{
if (e.Exception != null)
{
lbl_Errors.Text = e.Exception.Mes sage.ToString() ;
e.ExceptionHand led = true;
}
else
{
Response.Redire ct("~/PR/PR_Item.aspx?PR =" + tb_tPR.Text);
}
}
but then have to parse and switch() to get a meaningful message to the
user.
Is there a way to use a try/catch in this situation so I can handle the
different exceptions individually?
I guess you could rethrow e.Exception in a try block and catch that, but
it may wipe the stack trace and change the exception type (haven't tried
it). Something like:
if (e.Exception != null)
{
try
{
throw e.Exception;
}
catch (StackOverflowE xception ex)
{
// Do stuff
}
catch (Exception ex)
{
// Do other stuff
}
}