473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

My UnhandledExceptionHandler Won't Fire

I'm new to Visual Studior C# .Net 2003 on Vista, and have been uable to get
my UnhandledExceptionHandler() to fire.

I have added these lines to Main() before the Application.Run():
AppDomain adCurrent = AppDomain.CurrentDomain;
adCurrent.UnhandledException += new
UnhandledExceptionEventHandler(UnhandledExceptionH andler);

It kicks out the regular debugging error, but never gets to my own event
handler. (I'm trying to learn exception handling, so I'm purposely not
handling the error at the moment.)

Is there a 'using' statement or a setting I should be using? There are no
compile errors.

Mar 30 '07 #1
5 1680
Victor,
This is most likely because you are doing your testing in the Visual Studio
IDE in debug mode, where the behavior is much different than when your
applicaition is running as a release - built app outside of the debugger
environment.
Hope that makes sense.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"victorcamp" wrote:
I'm new to Visual Studior C# .Net 2003 on Vista, and have been uable to get
my UnhandledExceptionHandler() to fire.

I have added these lines to Main() before the Application.Run():
AppDomain adCurrent = AppDomain.CurrentDomain;
adCurrent.UnhandledException += new
UnhandledExceptionEventHandler(UnhandledExceptionH andler);

It kicks out the regular debugging error, but never gets to my own event
handler. (I'm trying to learn exception handling, so I'm purposely not
handling the error at the moment.)

Is there a 'using' statement or a setting I should be using? There are no
compile errors.

Mar 30 '07 #2
I still have only a small understanding of the Visual Studio environment.

I tried just double-clicking the .exe, but that didn't fire it. The error
that did come up then suggested turning on JIT in the config with
<system.windows.forms jitDebugging="true" />, but there are lots of .config
files to chose from. I chose devenv.exe.config, but that didn't change
anything either.

I'm following through exercises in the Microsoft certification training
book, and it says I should be able to raise it right there in the Visual
Studio environment. I also tried the example exercises included with the
book, and they didn't fire it either. Without the ability to see my own
UnhandledExceptionHandler fire, I'm left with never using it in an app.

I would appreciate any help you can provide.

"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:ED**********************************@microsof t.com...
Victor,
This is most likely because you are doing your testing in the Visual
Studio
IDE in debug mode, where the behavior is much different than when your
applicaition is running as a release - built app outside of the debugger
environment.
Hope that makes sense.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"victorcamp" wrote:
>I'm new to Visual Studior C# .Net 2003 on Vista, and have been uable to
get
my UnhandledExceptionHandler() to fire.

I have added these lines to Main() before the Application.Run():
AppDomain adCurrent = AppDomain.CurrentDomain;
adCurrent.UnhandledException += new
UnhandledExceptionEventHandler(UnhandledException Handler);

It kicks out the regular debugging error, but never gets to my own event
handler. (I'm trying to learn exception handling, so I'm purposely not
handling the error at the moment.)

Is there a 'using' statement or a setting I should be using? There are no
compile errors.

Mar 30 '07 #3
OK. You could post more complete "just enough" sample code so readers can see
what you are doing. Also, this summary I did a while ago may help:
http://www.eggheadcafe.com/articles/20051205.asp
Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"victorcamp" wrote:
I still have only a small understanding of the Visual Studio environment.

I tried just double-clicking the .exe, but that didn't fire it. The error
that did come up then suggested turning on JIT in the config with
<system.windows.forms jitDebugging="true" />, but there are lots of .config
files to chose from. I chose devenv.exe.config, but that didn't change
anything either.

I'm following through exercises in the Microsoft certification training
book, and it says I should be able to raise it right there in the Visual
Studio environment. I also tried the example exercises included with the
book, and they didn't fire it either. Without the ability to see my own
UnhandledExceptionHandler fire, I'm left with never using it in an app.

I would appreciate any help you can provide.

"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:ED**********************************@microsof t.com...
Victor,
This is most likely because you are doing your testing in the Visual
Studio
IDE in debug mode, where the behavior is much different than when your
applicaition is running as a release - built app outside of the debugger
environment.
Hope that makes sense.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"victorcamp" wrote:
I'm new to Visual Studior C# .Net 2003 on Vista, and have been uable to
get
my UnhandledExceptionHandler() to fire.

I have added these lines to Main() before the Application.Run():
AppDomain adCurrent = AppDomain.CurrentDomain;
adCurrent.UnhandledException += new
UnhandledExceptionEventHandler(UnhandledExceptionH andler);

It kicks out the regular debugging error, but never gets to my own event
handler. (I'm trying to learn exception handling, so I'm purposely not
handling the error at the moment.)

Is there a 'using' statement or a setting I should be using? There are no
compile errors.


Mar 31 '07 #4
The example I'm using is right out of the Que Certification book: "MCAD/MCSD
Developing and Implementing Windows-based Applications with Visual C# .NET
and Visual Studio .NET" for Exam 70-316, Ch. 3, Step By Step 3.5, "Logging
Unhandled Exceptions in the Windows Event Log".

Environment:
Microsoft Development Environment 2003 v7.1.6030
Microsoft .NET Framework 1.1 v1.1.4322
Windows Vista

My code matches the example files included with the book's CD, and neither
ever gets to the created UnhandledExceptionHandler(). Another example I
pulled from Microsoft documentation, where the error is thrown manually (via
'throw'), does get to the handler. So the difference is that one purposely
throws it, which does get there, and the book's example relies on a real
error (e.g., a divide-by-zero exception), which doesn't get there.

3 TextBox: txtMiles, txtGallons, txtEfficiency; 1 Button: btnCalculate
1 'using' in addition to those automatically supplied by the designer: using
System.Diagnostics;

Start Code
=====

[STAThread]
static void Main()
{
AppDomain adCurrent = AppDomain.CurrentDomain;
adCurrent.UnhandledException += new
UnhandledExceptionEventHandler(UnhandledExceptionH andler);
Application.Run(new StepByStep3_05());
}

private static void UnhandledExceptionHandler(object sender,
UnhandledExceptionEventArgs ue)
{
Exception unhandledException = (Exception) ue.ExceptionObject;
if (!EventLog.SourceExists("Mileage Efficiency Calculator"))
{
EventLog.CreateEventSource("Mileage Efficiency Calculator",
"Mileage Efficiency Calculator Log");
}
EventLog eventLog = new EventLog();
eventLog.Source = "Mileage Efficiency Calculator";
eventLog.WriteEntry(unhandledException.Message);
MessageBox.Show("An exception occurred: Created an entry in the log file");
}

private void btnCalculate_Click(object sender, System.EventArgs e)
{
decimal decMiles = Convert.ToDecimal(txtMiles.Text);
decimal decGallons = Convert.ToDecimal(txtGallons.Text);
decimal decEfficiency = (decMiles / decGallons);
txtEfficiency.Text = String.Format("{0:n}", decEfficiency);
}

=====
End Code

I do not care whether it records the error in an event log or not. I'd take
anything just to see a message box from UnhandledExceptionHandler() that
shows it got there. When anything is amiss durring btnCalculate(), it shows
the standard debugging dialog, but never gets to my event handler, whether
or not I choose Debug or Continue. The book expects I'll see my own message
box when I run it within the development environment and purposely enter
something wrong on the form.

What gives?

Mar 31 '07 #5
The example I'm using is right out of the Que Certification book: "MCAD/MCSD
Developing and Implementing Windows-based Applications with Visual C# .NET
and Visual Studio .NET" for Exam 70-316, Ch. 3, Step By Step 3.5, "Logging
Unhandled Exceptions in the Windows Event Log".

Environment:
Microsoft Development Environment 2003 v7.1.6030
Microsoft .NET Framework 1.1 v1.1.4322
Windows Vista

My code matches the example files included with the book's CD, and neither
ever gets to the created UnhandledExceptionHandler(). Another example I
pulled from Microsoft documentation, where the error is thrown manually (via
'throw'), does get to the handler. So the difference is that one purposely
throws it, which does get there, and the book's example relies on a real
error (e.g., a divide-by-zero exception), which doesn't get there.

3 TextBox: txtMiles, txtGallons, txtEfficiency; 1 Button: btnCalculate
1 'using' in addition to those automatically supplied by the designer: using
System.Diagnostics;

Start Code
=====

[STAThread]
static void Main()
{
AppDomain adCurrent = AppDomain.CurrentDomain;
adCurrent.UnhandledException += new
UnhandledExceptionEventHandler(UnhandledExceptionH andler);
Application.Run(new StepByStep3_05());
}

private static void UnhandledExceptionHandler(object sender,
UnhandledExceptionEventArgs ue)
{
Exception unhandledException = (Exception) ue.ExceptionObject;
if (!EventLog.SourceExists("Mileage Efficiency Calculator"))
{
EventLog.CreateEventSource("Mileage Efficiency Calculator",
"Mileage Efficiency Calculator Log");
}
EventLog eventLog = new EventLog();
eventLog.Source = "Mileage Efficiency Calculator";
eventLog.WriteEntry(unhandledException.Message);
MessageBox.Show("An exception occurred: Created an entry in the log file");
}

private void btnCalculate_Click(object sender, System.EventArgs e)
{
decimal decMiles = Convert.ToDecimal(txtMiles.Text);
decimal decGallons = Convert.ToDecimal(txtGallons.Text);
decimal decEfficiency = (decMiles / decGallons);
txtEfficiency.Text = String.Format("{0:n}", decEfficiency);
}

=====
End Code

I do not care whether it records the error in an event log or not. I'd take
anything just to see a message box from UnhandledExceptionHandler() that
shows it got there. When anything is amiss durring btnCalculate(), it shows
the standard debugging dialog, but never gets to my event handler, whether
or not I choose Debug or Continue. The book expects I'll see my own message
box when I run it within the development environment and purposely enter
something wrong on the form.

What gives?

Mar 31 '07 #6

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

Similar topics

10
by: Wayne Aprato | last post by:
I have a database that was written in Access 2003 using the Access 2000 file format. When I run the mdb in Access 2003 everything works fine. If I run it in Access 2000 the timer event won't fire...
2
by: Steph | last post by:
I am working on a Windows Forms App. I have attached a standard UnhandledExceptionEventHandler to the current domain to catch unexpected errors. In my application, when I trigger an unhandled...
2
by: Sam Miller | last post by:
Hi, I have a button event that won't fire. I left it on Friday and it worked fine. I came back in on Monday and it won't fire. I tried putting another button and just putting a...
1
by: Ben | last post by:
i'm having trouble getting a custom validator to fire on one of my webforms. i dragged a custom validator onto the form, left all the properties on default, double clicked it, and typed this in the...
5
by: Bob | last post by:
I've got a .NET Framework V1.1 web service running on a Windows 2003 Server that has 2 web methods that are called from a web application on the same server. One is a fire-and-forget method that...
2
by: Ryan Liu | last post by:
Hi, I need the MouseDown event be trigged everytime when you press mouse in a datagrid (System.Windows.Forms). But seems mouse event will only fire once, and it seems changed to edit mode...
3
by: Beavis | last post by:
I hate to repost a message, but I am still at the same point where I was when I originally posted, and hopefully someone else will see this one... Ok, so I have gone off and documented the...
3
by: goscottie | last post by:
I have two comboboxes databound at run time. I can make a selection on first one to filter the second one. This works good with applying DataView RowFilter on second combobox. But at that...
3
by: Crazy Cat | last post by:
Hi all, I am developing an asp.net 2.0 application in Visual Studio 2005. On my page I have a simple datalist that is bound programmatically to a collection of simple objects. On this page I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...

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.