PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
RE: Exception not caught by a Try-Catch block
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
RE: Exception not caught by a Try-Catch block
![]() |
RE: Exception not caught by a Try-Catch block |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Sadly, this silly behaviour is by design:
http://support.microsoft.com/defaul...kb/324653/en-us I personally think the design should be changed so the .NET exception handler on the child forms message pump can be confgured to look up the call stack for another form or a call to show/showdialog and rethrow if found. -- Ciaran O'Donnell http://wannabedeveloper.spaces.live.com "javiguti" wrote: > Hi, > > I'm having trouble with exceptions, apparently in some cases even if I have > a Try Catch block they skip it and bubble up to the CLR. Here's the sample > steps to reproduce. I observed this behaviour oin .NET2.0 VS2005 but happens > in .NET1.1 as well: > > 1. Create a new VB WinForms application > 2. Open the file Form1.vb and replace all its code by this > > Public Class Form1 > Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) > Dim f As New Form2 > Try > f.ShowDialog() > Catch ex As Exception > MessageBox.Show("Exception Caught in Form1") > End Try > End Sub > End Class > > 3. Add a new form, "Form2.vb" to the project. > 4. Open the file Form2.vb and replace all its code by this > > Public Class Form2 > Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) > Throw New Exception("My Exception") > End Sub > End Class > > 5. Start With Debug (F5). As expetcted, the exception thrown in Form2 is > caught by Form1 and the messagebox "Exception Caught in Form1" is shown. > Close the messagebox. > > 6. Start Without Debugging (Ctrl + F5). THE EXCEPTION SKIPS THE TRY CATCH > BLOCK so becomes an Unhandled Exception. It bubbles up to the CLR which shows > the usual ugly crash messagebox. > > Anybody can explain to me the reason of this behaviour? Why is the exception > not caught by my TryCatch block?? |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Thanks Ciaran,
I was much afraid that I would get such an answer, "by design" fits many bugs :P. And it hasn't been fixed in .NET2.0 so I guess it's going to be like this for a while, I'll have to find an alternative way to do this (but surely it won't be near as elegant as with exceptions) thanks again for your response javi "Ciaran O''''Donnell" wrote: > Sadly, this silly behaviour is by design: > http://support.microsoft.com/defaul...kb/324653/en-us > > I personally think the design should be changed so the .NET exception > handler on the child forms message pump can be confgured to look up the call > stack for another form or a call to show/showdialog and rethrow if found. > > > -- > Ciaran O'Donnell > http://wannabedeveloper.spaces.live.com > > > "javiguti" wrote: > > > Hi, > > > > I'm having trouble with exceptions, apparently in some cases even if I have > > a Try Catch block they skip it and bubble up to the CLR. Here's the sample > > steps to reproduce. I observed this behaviour oin .NET2.0 VS2005 but happens > > in .NET1.1 as well: > > > > 1. Create a new VB WinForms application > > 2. Open the file Form1.vb and replace all its code by this > > > > Public Class Form1 > > Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) > > Dim f As New Form2 > > Try > > f.ShowDialog() > > Catch ex As Exception > > MessageBox.Show("Exception Caught in Form1") > > End Try > > End Sub > > End Class > > > > 3. Add a new form, "Form2.vb" to the project. > > 4. Open the file Form2.vb and replace all its code by this > > > > Public Class Form2 > > Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) > > Throw New Exception("My Exception") > > End Sub > > End Class > > > > 5. Start With Debug (F5). As expetcted, the exception thrown in Form2 is > > caught by Form1 and the messagebox "Exception Caught in Form1" is shown. > > Close the messagebox. > > > > 6. Start Without Debugging (Ctrl + F5). THE EXCEPTION SKIPS THE TRY CATCH > > BLOCK so becomes an Unhandled Exception. It bubbles up to the CLR which shows > > the usual ugly crash messagebox. > > > > Anybody can explain to me the reason of this behaviour? Why is the exception > > not caught by my TryCatch block?? |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

