473,883 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Try/Catch for Events

I am trying to capture event exceptions using try/catch.
I can get all exceptions with:

protected void dv_PR_ItemInser ted(object sender,
DetailsViewInse rtedEventArgs 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?
Jun 27 '08 #1
3 1090
"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,
DetailsViewInse rtedEventArgs 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
}
}

Jun 27 '08 #2
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
}
}

Jun 27 '08 #3

"randy.buchholz " <ra************ @dads.state.tx. uswrote in message
news:uv******** ******@TK2MSFTN GP04.phx.gbl...
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.
It depends on what you are expecting to be thrown. I don't think looking
through a list of exceptions will help much. You may be better off breaking
the system yourself and seeing what gets thrown by stepping into the code.

Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5057
by: Martin Ortiz | last post by:
Which is best approach? Should Try + Catch be used to only deal with "catastrophic" events (like divide by zero, non-existant file, etc...etc...) Or should Try + Catch be used IN PLACE of regular defensive programming? (ie if file exists do this, if not do something else) Or should Try + Catch be used TO SUPPLAMENT regular defensive programming?
11
2597
by: Terry Olsen | last post by:
How can I catch a right-click on a DropDownMenuItem?
5
3409
by: Simon Tamman {Uchiha Jax} | last post by:
Now this is bugging me. I just released software for a client and they have reported an unhandled stack overflow exception. My first concern is that the entirity of the UI and any threaded operations are all within Try Catches to help me locate the problem and the origination of any problem by specifiying an error code in the "Catch" section. So theoretically this shouldn't have been possible (at which point we all say "yeah,...
1
2031
by: Paul Fi | last post by:
how do i catch windows explorer and windows media player events in a .NET application, is it possible, say i double clicked on a media file inside windows media player and i wanted that event to trigger my .NET app to do something. *** Sent via Developersdex http://www.developersdex.com ***
5
1837
by: sleepinglord | last post by:
An example: I have a select input. I wanna catch those onclick events which is not a onchange events. How to implement it? And in general, there's some basic kinds of events, and I wanna catch the events which is a composition of the basic events. How to? Where can I find some examples£¿
2
2288
by: gazelle04 | last post by:
I want to catch events between subforms whenever I changed data on the first form and click on the second form. I'm on the main form. The main form consists of two subforms. I want to catch the editing of records on both. Let's say I changed data on the first subform and then I went to the next subform. I used LostFocus, DeActivate, Exit events but its not cathing the procedure for confirming the update. Only the AfterUpdate event catches...
3
1478
by: SimeonArgus | last post by:
I have a situation that I can't seem to work around. I have a database that lists the buttons that my application should generate. These buttons are displayed if certain conditions are met and all previous button clicks make sense. Sounds simple, right? Here's the catch. C# Processes FormLoad first, then Button Clicks, so if I build the page in FormLoad, the wrong buttons may appear, because the "hide the green buttons" click hasn't been...
2
19303
by: Tony Johansson | last post by:
Hello! I have created a Control that consist of a label and a textbox.I have called this class ctlLabelTextbox. public partial class ctlLabelTextbox : UserControl { .... } The class that I have created for this purpose is derived from class UserControl.
11
1495
by: darrel | last post by:
Trying to get back into .net again after being out of it for a while. I'm trying to figure out the proper way to handle multiple events via a try catch. What I'm confused about is the proper method to handle, say, 3 separate events: A, B, and C. I only want all 3 to execute if all 3 can successfully execute. Is that what a try-catch is for, or is a try/catch mainly for individual
0
9792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11147
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10855
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9577
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7974
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7133
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5801
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3236
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.