Click here to Skip to main content
15,915,319 members
Home / Discussions / C#
   

C#

 
AnswerRe: static class for database access? Pin
Luis Alonso Ramos2-Aug-05 9:13
Luis Alonso Ramos2-Aug-05 9:13 
GeneralRe: static class for database access? Pin
theStorminMormon2-Aug-05 9:16
theStorminMormon2-Aug-05 9:16 
GeneralRe: static class for database access? Pin
Luis Alonso Ramos2-Aug-05 9:26
Luis Alonso Ramos2-Aug-05 9:26 
GeneralEmulate a twain interface Pin
Oliver Lange2-Aug-05 8:25
Oliver Lange2-Aug-05 8:25 
GeneralSupressing Security Error Dialog Pin
RB@Emphasys2-Aug-05 7:53
RB@Emphasys2-Aug-05 7:53 
GeneralRe: Supressing Security Error Dialog Pin
mav.northwind2-Aug-05 20:06
mav.northwind2-Aug-05 20:06 
GeneralRe: Supressing Security Error Dialog Pin
RB@Emphasys3-Aug-05 3:57
RB@Emphasys3-Aug-05 3:57 
GeneralRe: Supressing Security Error Dialog Pin
mav.northwind3-Aug-05 7:42
mav.northwind3-Aug-05 7:42 
Considering your question and some rather unexpected and not really obvious behaviour of .NET I doubt you do.
Your program and exception handling will behave differently when run in the debugger than when started outside, for example, catching exceptions when run in the debugger but showing the default "an unhandled exception..." dialog when run outside VS.

That's something I've had to learn the hard way, too.

Try the following:
Create a new Windows Forms Project.
Add a second form to the project (Form2).
Put a button (button1) on your Form1 and a button (button2) on Form2.
Encapsulate your Application.Run(new Form1()); in a try/catch.
In the button eventhandler for button1 write
try<br />
{<br />
 Form2 f2 = new Form2();<br />
 f2.ShowDialog();<br />
}<br />
catch (Exception ex)<br />
{<br />
 MessageBox.Show("Exception caught in button1_Click()\n"+ex.ToString());<br />
}

In the button eventhandler for button2 write
throw new ApplicationException("Test Exception");

Now run the application in the debugger, press button1 and then button2.
The exception is caught by the try/catch in button1_Click.

Now run the same application from explorer. The exception will NOT be caught, even though you have a try/catch in the button event handler AND in your Main() !

So either you do as I suggested and catch the exception where it's happening or consider adding an event handler for Application.ThreadException that's just rethrowing the exception from it's ThreadExceptionEventArgs. That way your application will behave the same in the debugger and outside.

Regards,
mav
GeneralCapturing The Build Date Into Code Pin
bneacetp2-Aug-05 7:22
bneacetp2-Aug-05 7:22 
GeneralRe: Capturing The Build Date Into Code Pin
hamster12-Aug-05 11:22
hamster12-Aug-05 11:22 
GeneralRe: Capturing The Build Date Into Code Pin
bneacetp2-Aug-05 14:13
bneacetp2-Aug-05 14:13 
GeneralRe: Capturing The Build Date Into Code Pin
hamster13-Aug-05 8:21
hamster13-Aug-05 8:21 
GeneralReordering DOCKED controls Pin
Radgar2-Aug-05 7:16
Radgar2-Aug-05 7:16 
GeneralRe: Reordering DOCKED controls Pin
Alomgir Miah2-Aug-05 7:21
Alomgir Miah2-Aug-05 7:21 
GeneralRe: Reordering DOCKED controls Pin
Judah Gabriel Himango2-Aug-05 10:33
sponsorJudah Gabriel Himango2-Aug-05 10:33 
GeneralRe: Reordering DOCKED controls Pin
Radgar2-Aug-05 13:11
Radgar2-Aug-05 13:11 
GeneralRe: Reordering DOCKED controls Pin
Judah Gabriel Himango2-Aug-05 16:19
sponsorJudah Gabriel Himango2-Aug-05 16:19 
GeneralRe: Reordering DOCKED controls Pin
Radgar2-Aug-05 16:27
Radgar2-Aug-05 16:27 
GeneralObject serialization Pin
Luis Alonso Ramos2-Aug-05 6:40
Luis Alonso Ramos2-Aug-05 6:40 
GeneralRe: Object serialization Pin
Alomgir Miah2-Aug-05 7:49
Alomgir Miah2-Aug-05 7:49 
GeneralRe: Object serialization Pin
Luis Alonso Ramos2-Aug-05 7:58
Luis Alonso Ramos2-Aug-05 7:58 
GeneralTiming Error when using System.Timers.Timer Pin
LiamD2-Aug-05 6:39
LiamD2-Aug-05 6:39 
GeneralRe: Timing Error when using System.Timers.Timer Pin
S. Senthil Kumar2-Aug-05 6:51
S. Senthil Kumar2-Aug-05 6:51 
GeneralRe: Timing Error when using System.Timers.Timer Pin
LiamD2-Aug-05 21:16
LiamD2-Aug-05 21:16 
GeneralRe: Timing Error when using System.Timers.Timer Pin
S. Senthil Kumar2-Aug-05 22:50
S. Senthil Kumar2-Aug-05 22:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.