473,398 Members | 2,403 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,398 software developers and data experts.

Exception Handling difference between Design-Time and Run-Time

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
Nov 21 '05 #1
11 5526
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
Nov 21 '05 #2
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

Nov 21 '05 #3
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
| >
| >
| >
Nov 21 '05 #4
I have tried changing the "Debug - Exceptions - Common Language Runtime>
Exception".
And it does not change the fact that the exception is caught when I run my
App in Design-Time Enviornment and it is not in Run-Time.

This is a major problem. If there is no way round this then are Microsoft
aware of the problem and is it going to be fixed?

Nick

"Jay B. Harlow [MVP - Outlook]" wrote:
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
| >
| >
| >

Nov 21 '05 #5
Nick,
I'm sorry the Debug - Exceptions only works if you don't have a Try/Catch
around the Form.Show.

I don't put Try/Catch's around Form.Show as they don't really do what one
might think they should (which may be the alledged bug you were referring
to). Instead I use global Exception handlers, as they largely do what I
would expect them to.

| This is a major problem. If there is no way round this then are Microsoft
| aware of the problem and is it going to be fixed?
I believe we may have a difference of opinion here, as I see the exception
being caught in the IDE as the "bug", while the behavior outside the IDE is
what I would expect to happen. Based on my explanation of how Win32 events
occur.

After all how your program behaves outside the IDE is how your program is
going to behave in the "wild".

Although I agree in the case of Form.Load (and only Form.Load) it could be
beneficial to have a Try/Catch around Form.Show catch the exception. I know
some developers think that a Try/Catch around Form.Show & its close cousin
Application.Run should catch any Exception that any Form/Control level event
doesn't handle...

However I will try to verify what VS.NET 2005 does later today.

On the surface, it appears that if you handle the
Application.ThreadException & simply rethrow the exception then the
Try/Catch around Form.Show will behave as you expect. HOWEVER!!! This can
have serious determents to your code elsewhere. As you can't be certain of
the order that event handlers were added to Application.ThreadException,
plus you may catch exceptions that weren't meant to be caught...

You might try something like:

Public Shared Sub Main()
AddHandler Application.ThreadException, AddressOf
Application_ThreadException

Application.EnableVisualStyles()
Application.DoEvents()
Application.Run(New MainForm)
End Sub

Private Shared Sub Application_ThreadException(ByVal sender As Object,
ByVal e As System.Threading.ThreadExceptionEventArgs)
MessageBox.Show("Application_ThreadException" & ControlChars.CrLf &
ControlChars.CrLf & e.Exception.ToString(), Application.ProductName)
Debug.WriteLine(e.Exception.ToString())
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim child As New ChildForm
Try
' HACK: Try & catch exceptions from ChildForm.Load
AddHandler Application.ThreadException, AddressOf
Show_ThreadException
child.Show()
Catch ex As Exception
MessageBox.Show("Button1_Click" & ControlChars.CrLf &
ControlChars.CrLf & ex.ToString(), Application.ProductName)
Debug.WriteLine(ex.ToString())
Finally
' HACK: Try & catch exceptions from ChildForm.Load
RemoveHandler Application.ThreadException, AddressOf
Show_ThreadException
End Try
End Sub

' HACK: Try & catch exceptions from ChildForm.Load
Private Shared Sub Show_ThreadException(ByVal sender As Object, ByVal e
As System.Threading.ThreadExceptionEventArgs)
MessageBox.Show("Show_ThreadException" & ControlChars.CrLf &
ControlChars.CrLf & e.Exception.ToString(), Application.ProductName)
Debug.WriteLine(e.Exception.ToString(), "Show_ThreadException")
Throw e.Exception
End Sub

I say "on the surface" as I did minimal testing from the IDE with both
'Debug - Start' & 'Debug - Start without Debugging' and testing from Windows
Explorer.
Hope this helps
Jay

"chopsnsauce" <ch*********@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
|I have tried changing the "Debug - Exceptions - Common Language Runtime>
| Exception".
| And it does not change the fact that the exception is caught when I run my
| App in Design-Time Enviornment and it is not in Run-Time.
|
| This is a major problem. If there is no way round this then are Microsoft
| aware of the problem and is it going to be fixed?
|
| Nick
|
<<snip>>
Nov 21 '05 #6
thanks for this Jay. its very helpful.

About the bug. I'm not saying either way whether its the IDE thats at fault
or the runtime. Just that the behaviour should be consistent in both.

PS i'm using VS.NET 2003, so if you can't duplicate it its time to think
about upgrading.

Nick

"Jay B. Harlow [MVP - Outlook]" wrote:
Nick,
I'm sorry the Debug - Exceptions only works if you don't have a Try/Catch
around the Form.Show.

I don't put Try/Catch's around Form.Show as they don't really do what one
might think they should (which may be the alledged bug you were referring
to). Instead I use global Exception handlers, as they largely do what I
would expect them to.

| This is a major problem. If there is no way round this then are Microsoft
| aware of the problem and is it going to be fixed?
I believe we may have a difference of opinion here, as I see the exception
being caught in the IDE as the "bug", while the behavior outside the IDE is
what I would expect to happen. Based on my explanation of how Win32 events
occur.

After all how your program behaves outside the IDE is how your program is
going to behave in the "wild".

Although I agree in the case of Form.Load (and only Form.Load) it could be
beneficial to have a Try/Catch around Form.Show catch the exception. I know
some developers think that a Try/Catch around Form.Show & its close cousin
Application.Run should catch any Exception that any Form/Control level event
doesn't handle...

However I will try to verify what VS.NET 2005 does later today.

On the surface, it appears that if you handle the
Application.ThreadException & simply rethrow the exception then the
Try/Catch around Form.Show will behave as you expect. HOWEVER!!! This can
have serious determents to your code elsewhere. As you can't be certain of
the order that event handlers were added to Application.ThreadException,
plus you may catch exceptions that weren't meant to be caught...

You might try something like:

Public Shared Sub Main()
AddHandler Application.ThreadException, AddressOf
Application_ThreadException

Application.EnableVisualStyles()
Application.DoEvents()
Application.Run(New MainForm)
End Sub

Private Shared Sub Application_ThreadException(ByVal sender As Object,
ByVal e As System.Threading.ThreadExceptionEventArgs)
MessageBox.Show("Application_ThreadException" & ControlChars.CrLf &
ControlChars.CrLf & e.Exception.ToString(), Application.ProductName)
Debug.WriteLine(e.Exception.ToString())
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim child As New ChildForm
Try
' HACK: Try & catch exceptions from ChildForm.Load
AddHandler Application.ThreadException, AddressOf
Show_ThreadException
child.Show()
Catch ex As Exception
MessageBox.Show("Button1_Click" & ControlChars.CrLf &
ControlChars.CrLf & ex.ToString(), Application.ProductName)
Debug.WriteLine(ex.ToString())
Finally
' HACK: Try & catch exceptions from ChildForm.Load
RemoveHandler Application.ThreadException, AddressOf
Show_ThreadException
End Try
End Sub

' HACK: Try & catch exceptions from ChildForm.Load
Private Shared Sub Show_ThreadException(ByVal sender As Object, ByVal e
As System.Threading.ThreadExceptionEventArgs)
MessageBox.Show("Show_ThreadException" & ControlChars.CrLf &
ControlChars.CrLf & e.Exception.ToString(), Application.ProductName)
Debug.WriteLine(e.Exception.ToString(), "Show_ThreadException")
Throw e.Exception
End Sub

I say "on the surface" as I did minimal testing from the IDE with both
'Debug - Start' & 'Debug - Start without Debugging' and testing from Windows
Explorer.
Hope this helps
Jay

"chopsnsauce" <ch*********@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
|I have tried changing the "Debug - Exceptions - Common Language Runtime>
| Exception".
| And it does not change the fact that the exception is caught when I run my
| App in Design-Time Enviornment and it is not in Run-Time.
|
| This is a major problem. If there is no way round this then are Microsoft
| aware of the problem and is it going to be fixed?
|
| Nick
|
<<snip>>

Nov 21 '05 #7
Nick,
VS.NET 2005 has the same feature...

This feature makes me think of the Heisenberg Uncertainty Principle. "As
soon as you try and measure something you end up affecting the measure" or
in this case as soon as you try to debug your app, you modify the behavior
of your app. ;-)

The problem/feature seems to be related to the NativeWindow.Callback verses
NativeWindow.DebuggableCallback methods. NativeWindow.DebuggableCallback
appears in the call stack when you are running under VS.NET & you do not
have the global exception handler in the sub main... If outside VS.NET or
you have the global exception handler in the sub main, then I only see
NativeWindow.Callback... Note having the global exception handler in the
Try/Catch does not seem to effect which routine is used...
Seeing as I normally have the global exception handler in my sub main, to
catch unhandled exceptions in all my Control event methods, I've never
really noticed this behavior before... I strongly recommend having the
global exception handler in your sub main, for the reasons identified in the
this previously mentioned article:

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

Mainly that it prevents unhandled exceptions in your code & it allows you to
avoid duplicating try/catch blocks in each of your event procedures...

| About the bug. I'm not saying either way whether its the IDE thats at
fault
| or the runtime. Just that the behavior should be consistent in both.

As far as I can tell, once you have the above global exception handler the
behavior then becomes the same!

Hope this helps
Jay
"chopsnsauce" <ch*********@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
| thanks for this Jay. its very helpful.
|
| About the bug. I'm not saying either way whether its the IDE thats at
fault
| or the runtime. Just that the behaviour should be consistent in both.
|
| PS i'm using VS.NET 2003, so if you can't duplicate it its time to think
| about upgrading.
|
| Nick
|
<<snip>>
Nov 21 '05 #8
Thanks for that Jay, helps alot.

Can you tell me, are MS aware of the problem?
If not how do I report it to them.

Thanks,

Nick

"Jay B. Harlow [MVP - Outlook]" wrote:
Nick,
VS.NET 2005 has the same feature...

This feature makes me think of the Heisenberg Uncertainty Principle. "As
soon as you try and measure something you end up affecting the measure" or
in this case as soon as you try to debug your app, you modify the behavior
of your app. ;-)

The problem/feature seems to be related to the NativeWindow.Callback verses
NativeWindow.DebuggableCallback methods. NativeWindow.DebuggableCallback
appears in the call stack when you are running under VS.NET & you do not
have the global exception handler in the sub main... If outside VS.NET or
you have the global exception handler in the sub main, then I only see
NativeWindow.Callback... Note having the global exception handler in the
Try/Catch does not seem to effect which routine is used...
Seeing as I normally have the global exception handler in my sub main, to
catch unhandled exceptions in all my Control event methods, I've never
really noticed this behavior before... I strongly recommend having the
global exception handler in your sub main, for the reasons identified in the
this previously mentioned article:

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

Mainly that it prevents unhandled exceptions in your code & it allows you to
avoid duplicating try/catch blocks in each of your event procedures...

| About the bug. I'm not saying either way whether its the IDE thats at
fault
| or the runtime. Just that the behavior should be consistent in both.

As far as I can tell, once you have the above global exception handler the
behavior then becomes the same!

Hope this helps
Jay
"chopsnsauce" <ch*********@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
| thanks for this Jay. its very helpful.
|
| About the bug. I'm not saying either way whether its the IDE thats at
fault
| or the runtime. Just that the behaviour should be consistent in both.
|
| PS i'm using VS.NET 2003, so if you can't duplicate it its time to think
| about upgrading.
|
| Nick
|
<<snip>>

Nov 21 '05 #9
Nick,
You can report bugs & make suggestions on VS.NET 2005 here:

http://lab.msdn.microsoft.com/vs2005/

Hope this helps
Jay

"chopsnsauce" <ch*********@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
| Thanks for that Jay, helps alot.
|
| Can you tell me, are MS aware of the problem?
| If not how do I report it to them.
|
| Thanks,
|
| Nick
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > Nick,
| > VS.NET 2005 has the same feature...
| >
| > This feature makes me think of the Heisenberg Uncertainty Principle. "As
| > soon as you try and measure something you end up affecting the measure"
or
| > in this case as soon as you try to debug your app, you modify the
behavior
| > of your app. ;-)
| >
| > The problem/feature seems to be related to the NativeWindow.Callback
verses
| > NativeWindow.DebuggableCallback methods. NativeWindow.DebuggableCallback
| > appears in the call stack when you are running under VS.NET & you do not
| > have the global exception handler in the sub main... If outside VS.NET
or
| > you have the global exception handler in the sub main, then I only see
| > NativeWindow.Callback... Note having the global exception handler in the
| > Try/Catch does not seem to effect which routine is used...
| >
| >
| > Seeing as I normally have the global exception handler in my sub main,
to
| > catch unhandled exceptions in all my Control event methods, I've never
| > really noticed this behavior before... I strongly recommend having the
| > global exception handler in your sub main, for the reasons identified in
the
| > this previously mentioned article:
| >
| > http://msdn.microsoft.com/msdnmag/is...T/default.aspx
| >
| > Mainly that it prevents unhandled exceptions in your code & it allows
you to
| > avoid duplicating try/catch blocks in each of your event procedures...
| >
| > | About the bug. I'm not saying either way whether its the IDE thats at
| > fault
| > | or the runtime. Just that the behavior should be consistent in both.
| >
| > As far as I can tell, once you have the above global exception handler
the
| > behavior then becomes the same!
| >
| > Hope this helps
| > Jay
| >
| >
| > "chopsnsauce" <ch*********@discussions.microsoft.com> wrote in message
| > news:EE**********************************@microsof t.com...
| > | thanks for this Jay. its very helpful.
| > |
| > | About the bug. I'm not saying either way whether its the IDE thats at
| > fault
| > | or the runtime. Just that the behaviour should be consistent in both.
| > |
| > | PS i'm using VS.NET 2003, so if you can't duplicate it its time to
think
| > | about upgrading.
| > |
| > | Nick
| > |
| > <<snip>>
| >
| >
| >
Nov 21 '05 #10
Thanks

"Jay B. Harlow [MVP - Outlook]" wrote:
Nick,
You can report bugs & make suggestions on VS.NET 2005 here:

http://lab.msdn.microsoft.com/vs2005/

Hope this helps
Jay

"chopsnsauce" <ch*********@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
| Thanks for that Jay, helps alot.
|
| Can you tell me, are MS aware of the problem?
| If not how do I report it to them.
|
| Thanks,
|
| Nick
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > Nick,
| > VS.NET 2005 has the same feature...
| >
| > This feature makes me think of the Heisenberg Uncertainty Principle. "As
| > soon as you try and measure something you end up affecting the measure"
or
| > in this case as soon as you try to debug your app, you modify the
behavior
| > of your app. ;-)
| >
| > The problem/feature seems to be related to the NativeWindow.Callback
verses
| > NativeWindow.DebuggableCallback methods. NativeWindow.DebuggableCallback
| > appears in the call stack when you are running under VS.NET & you do not
| > have the global exception handler in the sub main... If outside VS.NET
or
| > you have the global exception handler in the sub main, then I only see
| > NativeWindow.Callback... Note having the global exception handler in the
| > Try/Catch does not seem to effect which routine is used...
| >
| >
| > Seeing as I normally have the global exception handler in my sub main,
to
| > catch unhandled exceptions in all my Control event methods, I've never
| > really noticed this behavior before... I strongly recommend having the
| > global exception handler in your sub main, for the reasons identified in
the
| > this previously mentioned article:
| >
| > http://msdn.microsoft.com/msdnmag/is...T/default.aspx
| >
| > Mainly that it prevents unhandled exceptions in your code & it allows
you to
| > avoid duplicating try/catch blocks in each of your event procedures...
| >
| > | About the bug. I'm not saying either way whether its the IDE thats at
| > fault
| > | or the runtime. Just that the behavior should be consistent in both.
| >
| > As far as I can tell, once you have the above global exception handler
the
| > behavior then becomes the same!
| >
| > Hope this helps
| > Jay
| >
| >
| > "chopsnsauce" <ch*********@discussions.microsoft.com> wrote in message
| > news:EE**********************************@microsof t.com...
| > | thanks for this Jay. its very helpful.
| > |
| > | About the bug. I'm not saying either way whether its the IDE thats at
| > fault
| > | or the runtime. Just that the behaviour should be consistent in both.
| > |
| > | PS i'm using VS.NET 2003, so if you can't duplicate it its time to
think
| > | about upgrading.
| > |
| > | Nick
| > |
| > <<snip>>
| >
| >
| >

Nov 21 '05 #11
Nick,
In case you were following this thread.
Here is an KB article that I found talking about this topic:

http://support.microsoft.com/?kbid=836674

Hope this helps
Jay

"chopsnsauce" <ch*********@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
| Thanks
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > Nick,
| > You can report bugs & make suggestions on VS.NET 2005 here:
| >
| > http://lab.msdn.microsoft.com/vs2005/
| >
| > Hope this helps
| > Jay
| >
| > "chopsnsauce" <ch*********@discussions.microsoft.com> wrote in message
| > news:53**********************************@microsof t.com...
| > | Thanks for that Jay, helps alot.
| > |
| > | Can you tell me, are MS aware of the problem?
| > | If not how do I report it to them.
| > |
| > | Thanks,
| > |
| > | Nick
| > |
| > | "Jay B. Harlow [MVP - Outlook]" wrote:
| > |
| > | > Nick,
| > | > VS.NET 2005 has the same feature...
| > | >
| > | > This feature makes me think of the Heisenberg Uncertainty Principle.
"As
| > | > soon as you try and measure something you end up affecting the
measure"
| > or
| > | > in this case as soon as you try to debug your app, you modify the
| > behavior
| > | > of your app. ;-)
| > | >
| > | > The problem/feature seems to be related to the NativeWindow.Callback
| > verses
| > | > NativeWindow.DebuggableCallback methods.
NativeWindow.DebuggableCallback
| > | > appears in the call stack when you are running under VS.NET & you do
not
| > | > have the global exception handler in the sub main... If outside
VS.NET
| > or
| > | > you have the global exception handler in the sub main, then I only
see
| > | > NativeWindow.Callback... Note having the global exception handler in
the
| > | > Try/Catch does not seem to effect which routine is used...
| > | >
| > | >
| > | > Seeing as I normally have the global exception handler in my sub
main,
| > to
| > | > catch unhandled exceptions in all my Control event methods, I've
never
| > | > really noticed this behavior before... I strongly recommend having
the
| > | > global exception handler in your sub main, for the reasons
identified in
| > the
| > | > this previously mentioned article:
| > | >
| > | > http://msdn.microsoft.com/msdnmag/is...T/default.aspx
| > | >
| > | > Mainly that it prevents unhandled exceptions in your code & it
allows
| > you to
| > | > avoid duplicating try/catch blocks in each of your event
procedures...
| > | >
| > | > | About the bug. I'm not saying either way whether its the IDE
thats at
| > | > fault
| > | > | or the runtime. Just that the behavior should be consistent in
both.
| > | >
| > | > As far as I can tell, once you have the above global exception
handler
| > the
| > | > behavior then becomes the same!
| > | >
| > | > Hope this helps
| > | > Jay
| > | >
| > | >
| > | > "chopsnsauce" <ch*********@discussions.microsoft.com> wrote in
message
| > | > news:EE**********************************@microsof t.com...
| > | > | thanks for this Jay. its very helpful.
| > | > |
| > | > | About the bug. I'm not saying either way whether its the IDE
thats at
| > | > fault
| > | > | or the runtime. Just that the behaviour should be consistent in
both.
| > | > |
| > | > | PS i'm using VS.NET 2003, so if you can't duplicate it its time
to
| > think
| > | > | about upgrading.
| > | > |
| > | > | Nick
| > | > |
| > | > <<snip>>
| > | >
| > | >
| > | >
| >
| >
| >
Nov 21 '05 #12

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

Similar topics

13
by: Aggelos I. Orfanakos | last post by:
Hello. In a program, I want to ensure that a socket closes (so I use try ... finally), but I also want to catch/handle a socket exception. This is what I have done: try: try: s = ... #...
28
by: Frank Puck | last post by:
Meanwhile there are at least 8 years that compilers exist, which provide a working implementation of C++ Exception Handling. Has anything changed meanwhile? From my point of view nothing has...
11
by: Master of C++ | last post by:
Hi, I am writing a simulation package in C++, and so far I've written about 8000 lines of code and have about 30 classes. I haven't used C++ exceptions so far (for various reasons). The only two...
3
by: Master of C++ | last post by:
Hi, I am an absolute newbie to Exception Handling, and I am trying to retrofit exception handling to a LOT of C++ code that I've written earlier. I am just looking for a bare-bones, low-tech...
5
by: juergen perlinger | last post by:
Hello out there. sometimes I need to have proper control of the floating point arithmetic of the C(and C++) runtime system, and using the f.p. exception handling of the C99 standard is quite...
5
by: Bevo | last post by:
In my enterprise application I'd like my DataAccess layer to be responsible for handling all database error situations and to basically throw custom exceptions according to whether db connection is...
1
by: maciek | last post by:
Hi, I was wondering if anyone could suggest me a book/article/tutorial on Exception Handling in multi tier Windows Apps. What are the best practices/ways to implement EH in multi tier...
10
by: pauldepstein | last post by:
I have read about exception handling in a few books and websites but am still confused on a basic point. I understand the try ... catch syntax. However, I have seen examples of using throw...
2
by: Wing Siu | last post by:
Dear All I would like to ask you an opinion of ASP.NET exception handling I am working in a software house and need to deliver a system to our customer. However, as we knew (of course it can...
6
by: asm23 | last post by:
Hi, everyone, I'm learning <<thinking c++>volume Two, and testing the code below. ///////////////////////////////////////////////////////////////////////////// //: C01:Wrapped.cpp #include...
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: 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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.