Nick,
| Is it possible to make the Design and Run-Time enviroments behave in the
| same way?
Have you tried turning the option I mentioned in the IDE off?
| Also catching the exception at the application level is OK but ideally I
| want to catch the exception at the frm.Show level.
| Are you saying that this is not possible in .NET???
Yes I'm saying its not possible, as that is not how Windows Forms in .NET
works. You could try adding a local handler, Form.Show, Remove the local
handler, however I'm not sure you will get "accurate" results, as another
event (another Win32 message) could throw an exception during the time you
had the local handler attached. Also the form exists for much longer then
the lifetime of Form.Show method.
I understand that the Form.Load event is raised in response to WM_CREATE
Win32 message.
The WM_CREATE message is sent in response to creating the handle to the
underlying Win32 window. When the framework translates Win32 message to
Control/Form Events it wraps raising those events in a Try/Catch that raises
the Application.ThreadException, as normally those messages are processed
via the "message pump", in .NET the "message pump" is the Application.Run
method. In Win32 the "message pump" is a loop that calls the GetMessage,
TranslateMessage, and DispatchMessage Win32 APIs.
Hope this helps
Jay
"chopsnsauce" <ch*********@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
| Thanks for the response Jay.
|
| More questions.
|
| Is it possible to make the Design and Run-Time enviroments behave in the
| same way?
| This is my first VB.NET project (moving from VB6.0) and this problem has
| REALLY caught me out.
|
| Also catching the exception at the application level is OK but ideally I
| want to catch the exception at the frm.Show level.
| Are you saying that this is not possible in .NET???
|
| Thanks,
|
| Nick
|
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > Nick,
| > | Say FORM1 throws an exception in the load event. Run this in the
| > | Design-Time enviroment and the exception is caught by the code. Run
it in
| > | Run-Time and the exception is unhandled.
| > The Design-Time enviroment defaults to "If the exception is not
handled -
| > break into the debugger" under "Debug - Exceptions - Common Language
Runtime
| > Exception".
| >
| > At runtime you do not have an exception handler that handles exceptions
in
| > WIndows Forms Events.
| >
| > Your try/catch block is only handling events that Form.Show itself
throws.
| >
| > To handle exceptions in the Form.Load event you need to use a Global
| > Exception Handler.
| >
| > Depending on the type of application you are creating, .NET has three
| > different global exception handlers.
| >
| > For ASP.NET look at:
| > System.Web.HttpApplication.Error event
| > Normally placed in your Global.asax file.
| >
| > For console applications look at:
| > System.AppDomain.UnhandledException event
| > Use AddHandler in your Sub Main.
| >
| > For Windows Forms look at:
| > System.Windows.Forms.Application.ThreadException event
| > Use AddHandler in your Sub Main.
| >
| > It can be beneficial to combine the above global handlers in your app,
as
| > well as wrap your Sub Main in a try catch itself.
| >
| > There is an article in the June 2004 MSDN Magazine that shows how to
| > implement the global exception handling in .NET that explains why & when
you
| > use multiple of the above handlers...
| >
| >
http://msdn.microsoft.com/msdnmag/is...T/default.aspx
| >
| > For example: In my Windows Forms apps I would have a handler attached to
the
| > Application.ThreadException event, plus a Try/Catch in my Main. The
| > Try/Catch in Main only catches exceptions if the constructor of the
MainForm
| > raises an exception, the Application.ThreadException handler will catch
all
| > uncaught exceptions from any form/control event handlers.
| >
| > Public Shared Sub Main()
| > AddHandler Application.ThreadException, AddressOf
| > Application_ThreadException
| > Application.EnableVisualStyles()
| > Application.DoEvents()
| > Try
| > Application.Run(New MainForm)
| > Catch ex As Exception
| > ' log ex for later diagnosis
| > ' optionally show "pretty" version to user
| > End Try
| > End Sub
| >
| > Private Shared Sub Application_ThreadException(ByVal sender As
Object,
| > ByVal e As System.Threading.ThreadExceptionEventArgs)
| >
| > ' Log the e.Exception for later diagnosis.
| > ' optionally show "pretty" version to user
| >
| > End Sub
| >
| > Hope this helps
| > Jay
| >
| >
| >
| > "chopsnsauce" <ch*********@discussions.microsoft.com> wrote in message
| > news:BF**********************************@microsof t.com...
| > | Here's the example:
| > |
| > | Dim frm As New FORM1
| > | Try
| > |
| > | frm.show
| > |
| > | Catch ex As Exception
| > |
| > | msgbox ex.message
| > |
| > | End Try
| > |
| > | Say FORM1 throws an exception in the load event. Run this in the
| > | Design-Time enviroment and the exception is caught by the code. Run
it in
| > | Run-Time and the exception is unhandled.
| > |
| > | Some people have said this is a bug. Can you (Microsoft) confirm this
for
| > | me please? And confirm whether its a bug in design or run-time? And
what
| > | the recomended work round for this is.
| > |
| > | Thanks,
| > |
| > | Nick Charnock
| > |
| > |
| > |
| > | ----------------
| > | This post is a suggestion for Microsoft, and Microsoft responds to the
| > | suggestions with the most votes. To vote for this suggestion, click
the "I
| > | Agree" button in the message pane. If you do not see the button,
follow
| > this
| > | link to open the suggestion in the Microsoft Web-based Newsreader and
then
| > | click "I Agree" in the message pane.
| > |
| > |
| >
http://www.microsoft.com/communities...t.languages.vb
| >
| >
| >