Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

try..catch catch the error only running inside of VS.NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dragos Hilbert - 07 Mar 2008 14:53 GMT
VS 2008 target .NET 3.5, release mode.
One windows form application project with 2 forms:
First form with a button with the next code:

           try
           {
               using ( SecondForm secondForm = new SecondForm() )
              {
                     secondForm.ShowDialog();
              }                
           }
           catch ( Exception )
           {

               MessageBox.Show( "Error" );

           }

Second form with a button with the next code:

throw new Exception();

When I run the solution with F5 everything it is ok:
See first form
press button
See second form
press button
Second form disappears
the message box is displayed

If I run outside of VS.NET or with CTRL+F5:
See first form
press button
See second form
press button
NET error message window is displayed (Second form is still on screen)

Have you any idea why?

Error is:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Exception: Exception of type 'System.Exception' was thrown.
  at UI2.SecondForm.button1_Click(Object sender, EventArgs e) in
C:\Code\Invat\UI2\SecondForm.cs:line 21
  at System.Windows.Forms.Control.OnClick(EventArgs e)
  at System.Windows.Forms.Button.OnClick(EventArgs e)
  at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
  at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
  at System.Windows.Forms.Control.WndProc(Message& m)
  at System.Windows.Forms.ButtonBase.WndProc(Message& m)
  at System.Windows.Forms.Button.WndProc(Message& m)
  at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
  at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
  at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies **************
mscorlib
   Assembly Version: 2.0.0.0
   Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
   CodeBase:
file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
UI2
   Assembly Version: 1.0.0.0
   Win32 Version: 1.0.0.0
   CodeBase: file:///C:/Code/Invat/UI2/bin/Release/UI2.exe
----------------------------------------
System.Windows.Forms
   Assembly Version: 2.0.0.0
   Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
   CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
   Assembly Version: 2.0.0.0
   Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
   CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
   Assembly Version: 2.0.0.0
   Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
   CodeBase:
file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
   <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Marc Gravell - 07 Mar 2008 15:23 GMT
This same problem was posted recently... basically, it means that your Load
event (or OnLoad override) is throwing an exception. For some freaky reasons
(I never saw a good answer) this won't see the exception handler in the
stack.

Marc
Ben Voigt [C++ MVP] - 11 Mar 2008 16:35 GMT
> This same problem was posted recently... basically, it means that
> your Load event (or OnLoad override) is throwing an exception. For
> some freaky reasons (I never saw a good answer) this won't see the
> exception handler in the stack.

The ShowDialog method sets up a modal message loop, this message loop must
have its own exception handler.

For example,
System.Windows.Forms.Application+ThreadContext.LocalModalMessageLoop catches
and discards all exceptions (I am not sure if that is the message loop
running in this case, it looks like it is, called from RunMessageLoopInner,
reason == 4).  There's some logic mixed in where a different path is
executed if ((this.ComponentManager is Application.ComponentManager)) and
that may explain the different behavior inside the debugger.

> Marc

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.