473,796 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Uncatchable Exception

Well, I'm still wondering around in the "land of the lost exception"...
It seems that controls that are bound to a class and the class throws an
error in the SET method of the bound member, the exception cannot be
caught. I have wrapped my entire application in all the global
exception handlers I can find, and still to no avail. In fact all the
Try/Catches and Exception event handlers are worthless...

Put on your advanced thinking caps, and help me solve this one, please!

To recreate the problem:
*************** *************** *************** ************
1. In a new WindowsForm project, add Module1 as follows:
*************** *************** *************** ************

'----------------------------------------------
'This module is right out of the text book for
'handling unhandled exceptions:
'----------------------------------------------
Module Module1
Public Sub main()
Try
SubMain()
Catch ex As Exception
HandleUnhandled Exception(ex)
End Try
End Sub
Private Sub SubMain()
AddHandler AppDomain.Curre ntDomain.Unhand ledException, AddressOf
OnUnhandledExce ption
AddHandler Application.Thr eadException, AddressOf
OnGuiUnhandedEx ception
Application.Run (New Form1)
End Sub

Private Sub OnUnhandledExce ption(ByVal sender As Object, ByVal e As
UnhandledExcept ionEventArgs)
HandleUnhandled Exception(e.Exc eptionObject)
End Sub
Private Sub OnGuiUnhandedEx ception(ByVal sender As Object, ByVal e
As System.Threadin g.ThreadExcepti onEventArgs)
HandleUnhandled Exception(e.Exc eption)
End Sub

Private Sub HandleUnhandled Exception(ByVal o As Object)
Dim e As Exception = DirectCast(o, Exception)
If Not e Is Nothing Then
Debug.WriteLine ("Exception = " + e.GetType().ToS tring)
Debug.WriteLine ("Message = " + e.Message)
Debug.WriteLine ("FullText = " + e.ToString())
Else
Debug.WriteLine ("Exception = " + o.GetType().ToS tring)
Debug.WriteLine ("FullText = " + o.ToString())
End If
MsgBox(e.Messag e)
End Sub

End Module

'----------------------------------------------
'Here is the class that the textbox will be
'bound to. Note how it throws an error if you
'try to change the Name property to "Bob"
'----------------------------------------------
Public Class XClass
Private myName As String = String.Empty
Public Property Name() As String
Get
Return myName
End Get
Set(ByVal Value As String)
If Value = "Bob" Then
Throw New Exception("Name Cannot Be Bob")
Else
myName = value
End If
End Set
End Property
End Class

*************** *************** *************** ************
2. Now add a form to the project with the following code:
*************** *************** *************** ************
Public Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows. Forms.TextBox
Friend WithEvents TextBox2 As System.Windows. Forms.TextBox
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.TextBox1 = New System.Windows. Forms.TextBox
Me.TextBox2 = New System.Windows. Forms.TextBox
Me.SuspendLayou t()
'
'TextBox1
'
Me.TextBox1.Loc ation = New System.Drawing. Point(24, 48)
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Siz e = New System.Drawing. Size(248, 20)
Me.TextBox1.Tab Index = 0
Me.TextBox1.Tex t = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Loc ation = New System.Drawing. Point(24, 80)
Me.TextBox2.Nam e = "TextBox2"
Me.TextBox2.Siz e = New System.Drawing. Size(248, 20)
Me.TextBox2.Tab Index = 1
Me.TextBox2.Tex t = "TextBox2"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 181)
Me.Controls.Add (Me.TextBox2)
Me.Controls.Add (Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private myXclass As New XClass
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
TextBox1.DataBi ndings.Add("Tex t", myXclass, "Name")
End Sub
End Class
*************** *************** *************** ************
3. Run the project and set textbox 1 to "Roger" note that you can still
tab to textbox2 or close the form...

4. Now change textbox1 to "Bob" -- you can no longer tab to another
control nor can you close the form... and despite all the error handling
in the program, you can't catch the error!

*************** *************** *************** ************
SO... WHO CAN FIGURE THIS ONE OUT??? BIG PRIZES, AWARDS, FAME AND GLORY
AWAIT YOU... (OR AT LEAST A BIG THANK YOU FROM ME, IF NOTHING ELSE!)
GOOD LUCK, AND THANK YOU IN ADVANCE!!!
*************** *************** *************** ************
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
7 1709
Interesting. It's because the data binder is ignoring the exception. The
property is being set by something in the framework, not your code.

I bet the Binding class is doing something like this:

Try
oXClass.Name = TextBox1.Text
Catch exc As Exception
'nothing here
End Try

The only way you're going to catch that exception is if the Binding were to
throw it:

Try
oXClass.Name = TextBox1.Text
Catch exc As Exception
Throw exc
End Try

I have never used the new data binding features because I work in a shop
were all we do is giant complex batch processing. Most of my stuff doesn't
even have a UI. But you might explore the features and docs of the data
binding gadgets and see if there's some method to call or property to set
(or another overload of DataBindings.Ad d()) that makes it operate in another
mode.

--
Peace & happy computing,

Mike Labosh, MCSD

Feed the children!
Save the whales!
Free the mallocs!
Nov 21 '05 #2
I was able to duplicate here. Very strange.

Take a look at this thread:

http://tinyurl.com/4ajkn

Seems to indicate that your XClass needs to be implementing some interfaces
in order to play nice with databinding. Not sure myself.

Good luck!
PS (You can send my prize anytime!)
Greg

"ZorpiedoMa n" <No********@Bea tles.com> wrote in message
news:e%******** ********@TK2MSF TNGP09.phx.gbl. ..
Well, I'm still wondering around in the "land of the lost exception"...
It seems that controls that are bound to a class and the class throws an
error in the SET method of the bound member, the exception cannot be
caught. I have wrapped my entire application in all the global
exception handlers I can find, and still to no avail. In fact all the
Try/Catches and Exception event handlers are worthless...

Put on your advanced thinking caps, and help me solve this one, please!

To recreate the problem:
*************** *************** *************** ************
1. In a new WindowsForm project, add Module1 as follows:
*************** *************** *************** ************

'----------------------------------------------
'This module is right out of the text book for
'handling unhandled exceptions:
'----------------------------------------------
Module Module1
Public Sub main()
Try
SubMain()
Catch ex As Exception
HandleUnhandled Exception(ex)
End Try
End Sub
Private Sub SubMain()
AddHandler AppDomain.Curre ntDomain.Unhand ledException, AddressOf
OnUnhandledExce ption
AddHandler Application.Thr eadException, AddressOf
OnGuiUnhandedEx ception
Application.Run (New Form1)
End Sub

Private Sub OnUnhandledExce ption(ByVal sender As Object, ByVal e As
UnhandledExcept ionEventArgs)
HandleUnhandled Exception(e.Exc eptionObject)
End Sub
Private Sub OnGuiUnhandedEx ception(ByVal sender As Object, ByVal e
As System.Threadin g.ThreadExcepti onEventArgs)
HandleUnhandled Exception(e.Exc eption)
End Sub

Private Sub HandleUnhandled Exception(ByVal o As Object)
Dim e As Exception = DirectCast(o, Exception)
If Not e Is Nothing Then
Debug.WriteLine ("Exception = " + e.GetType().ToS tring)
Debug.WriteLine ("Message = " + e.Message)
Debug.WriteLine ("FullText = " + e.ToString())
Else
Debug.WriteLine ("Exception = " + o.GetType().ToS tring)
Debug.WriteLine ("FullText = " + o.ToString())
End If
MsgBox(e.Messag e)
End Sub

End Module

'----------------------------------------------
'Here is the class that the textbox will be
'bound to. Note how it throws an error if you
'try to change the Name property to "Bob"
'----------------------------------------------
Public Class XClass
Private myName As String = String.Empty
Public Property Name() As String
Get
Return myName
End Get
Set(ByVal Value As String)
If Value = "Bob" Then
Throw New Exception("Name Cannot Be Bob")
Else
myName = value
End If
End Set
End Property
End Class

*************** *************** *************** ************
2. Now add a form to the project with the following code:
*************** *************** *************** ************
Public Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows. Forms.TextBox
Friend WithEvents TextBox2 As System.Windows. Forms.TextBox
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.TextBox1 = New System.Windows. Forms.TextBox
Me.TextBox2 = New System.Windows. Forms.TextBox
Me.SuspendLayou t()
'
'TextBox1
'
Me.TextBox1.Loc ation = New System.Drawing. Point(24, 48)
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Siz e = New System.Drawing. Size(248, 20)
Me.TextBox1.Tab Index = 0
Me.TextBox1.Tex t = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Loc ation = New System.Drawing. Point(24, 80)
Me.TextBox2.Nam e = "TextBox2"
Me.TextBox2.Siz e = New System.Drawing. Size(248, 20)
Me.TextBox2.Tab Index = 1
Me.TextBox2.Tex t = "TextBox2"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 181)
Me.Controls.Add (Me.TextBox2)
Me.Controls.Add (Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private myXclass As New XClass
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
TextBox1.DataBi ndings.Add("Tex t", myXclass, "Name")
End Sub
End Class
*************** *************** *************** ************
3. Run the project and set textbox 1 to "Roger" note that you can still
tab to textbox2 or close the form...

4. Now change textbox1 to "Bob" -- you can no longer tab to another
control nor can you close the form... and despite all the error handling
in the program, you can't catch the error!

*************** *************** *************** ************
SO... WHO CAN FIGURE THIS ONE OUT??? BIG PRIZES, AWARDS, FAME AND GLORY
AWAIT YOU... (OR AT LEAST A BIG THANK YOU FROM ME, IF NOTHING ELSE!)
GOOD LUCK, AND THANK YOU IN ADVANCE!!!
*************** *************** *************** ************
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #3
Hi,

System.Exceptio n is thrown when ever an error is thrown. The
exception class inherits from system.applicat ionexception. They are thrown
when a non-fatal application occurs. Try catching a system.exceptio n
instead.

Try
SubMain()
Catch ex As System.Exceptio n
HandleUnhandled Exception(ex)
End Try

Ken
-------------------------
"ZorpiedoMa n" <No********@Bea tles.com> wrote in message
news:e%******** ********@TK2MSF TNGP09.phx.gbl. ..
Well, I'm still wondering around in the "land of the lost exception"...
It seems that controls that are bound to a class and the class throws an
error in the SET method of the bound member, the exception cannot be
caught. I have wrapped my entire application in all the global
exception handlers I can find, and still to no avail. In fact all the
Try/Catches and Exception event handlers are worthless...

Put on your advanced thinking caps, and help me solve this one, please!

To recreate the problem:
*************** *************** *************** ************
1. In a new WindowsForm project, add Module1 as follows:
*************** *************** *************** ************

'----------------------------------------------
'This module is right out of the text book for
'handling unhandled exceptions:
'----------------------------------------------
Module Module1
Public Sub main()
Try
SubMain()
Catch ex As Exception
HandleUnhandled Exception(ex)
End Try
End Sub
Private Sub SubMain()
AddHandler AppDomain.Curre ntDomain.Unhand ledException, AddressOf
OnUnhandledExce ption
AddHandler Application.Thr eadException, AddressOf
OnGuiUnhandedEx ception
Application.Run (New Form1)
End Sub

Private Sub OnUnhandledExce ption(ByVal sender As Object, ByVal e As
UnhandledExcept ionEventArgs)
HandleUnhandled Exception(e.Exc eptionObject)
End Sub
Private Sub OnGuiUnhandedEx ception(ByVal sender As Object, ByVal e
As System.Threadin g.ThreadExcepti onEventArgs)
HandleUnhandled Exception(e.Exc eption)
End Sub

Private Sub HandleUnhandled Exception(ByVal o As Object)
Dim e As Exception = DirectCast(o, Exception)
If Not e Is Nothing Then
Debug.WriteLine ("Exception = " + e.GetType().ToS tring)
Debug.WriteLine ("Message = " + e.Message)
Debug.WriteLine ("FullText = " + e.ToString())
Else
Debug.WriteLine ("Exception = " + o.GetType().ToS tring)
Debug.WriteLine ("FullText = " + o.ToString())
End If
MsgBox(e.Messag e)
End Sub

End Module

'----------------------------------------------
'Here is the class that the textbox will be
'bound to. Note how it throws an error if you
'try to change the Name property to "Bob"
'----------------------------------------------
Public Class XClass
Private myName As String = String.Empty
Public Property Name() As String
Get
Return myName
End Get
Set(ByVal Value As String)
If Value = "Bob" Then
Throw New Exception("Name Cannot Be Bob")
Else
myName = value
End If
End Set
End Property
End Class

*************** *************** *************** ************
2. Now add a form to the project with the following code:
*************** *************** *************** ************
Public Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows. Forms.TextBox
Friend WithEvents TextBox2 As System.Windows. Forms.TextBox
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.TextBox1 = New System.Windows. Forms.TextBox
Me.TextBox2 = New System.Windows. Forms.TextBox
Me.SuspendLayou t()
'
'TextBox1
'
Me.TextBox1.Loc ation = New System.Drawing. Point(24, 48)
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Siz e = New System.Drawing. Size(248, 20)
Me.TextBox1.Tab Index = 0
Me.TextBox1.Tex t = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Loc ation = New System.Drawing. Point(24, 80)
Me.TextBox2.Nam e = "TextBox2"
Me.TextBox2.Siz e = New System.Drawing. Size(248, 20)
Me.TextBox2.Tab Index = 1
Me.TextBox2.Tex t = "TextBox2"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 181)
Me.Controls.Add (Me.TextBox2)
Me.Controls.Add (Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private myXclass As New XClass
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
TextBox1.DataBi ndings.Add("Tex t", myXclass, "Name")
End Sub
End Class
*************** *************** *************** ************
3. Run the project and set textbox 1 to "Roger" note that you can still
tab to textbox2 or close the form...

4. Now change textbox1 to "Bob" -- you can no longer tab to another
control nor can you close the form... and despite all the error handling
in the program, you can't catch the error!

*************** *************** *************** ************
SO... WHO CAN FIGURE THIS ONE OUT??? BIG PRIZES, AWARDS, FAME AND GLORY
AWAIT YOU... (OR AT LEAST A BIG THANK YOU FROM ME, IF NOTHING ELSE!)
GOOD LUCK, AND THANK YOU IN ADVANCE!!!
*************** *************** *************** ************
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #4
Hi,

System.Exceptio n is thrown when ever an error is thrown. The
exception class inherits from system.applicat ionexception. They are thrown
when a non-fatal application occurs. Try catching a system.exceptio n
instead.

Try
SubMain()
Catch ex As System.Exceptio n
HandleUnhandled Exception(ex)
End Try

Ken
-------------------------
"ZorpiedoMa n" <No********@Bea tles.com> wrote in message
news:e%******** ********@TK2MSF TNGP09.phx.gbl. ..
Well, I'm still wondering around in the "land of the lost exception"...
It seems that controls that are bound to a class and the class throws an
error in the SET method of the bound member, the exception cannot be
caught. I have wrapped my entire application in all the global
exception handlers I can find, and still to no avail. In fact all the
Try/Catches and Exception event handlers are worthless...

Put on your advanced thinking caps, and help me solve this one, please!

To recreate the problem:
*************** *************** *************** ************
1. In a new WindowsForm project, add Module1 as follows:
*************** *************** *************** ************

'----------------------------------------------
'This module is right out of the text book for
'handling unhandled exceptions:
'----------------------------------------------
Module Module1
Public Sub main()
Try
SubMain()
Catch ex As Exception
HandleUnhandled Exception(ex)
End Try
End Sub
Private Sub SubMain()
AddHandler AppDomain.Curre ntDomain.Unhand ledException, AddressOf
OnUnhandledExce ption
AddHandler Application.Thr eadException, AddressOf
OnGuiUnhandedEx ception
Application.Run (New Form1)
End Sub

Private Sub OnUnhandledExce ption(ByVal sender As Object, ByVal e As
UnhandledExcept ionEventArgs)
HandleUnhandled Exception(e.Exc eptionObject)
End Sub
Private Sub OnGuiUnhandedEx ception(ByVal sender As Object, ByVal e
As System.Threadin g.ThreadExcepti onEventArgs)
HandleUnhandled Exception(e.Exc eption)
End Sub

Private Sub HandleUnhandled Exception(ByVal o As Object)
Dim e As Exception = DirectCast(o, Exception)
If Not e Is Nothing Then
Debug.WriteLine ("Exception = " + e.GetType().ToS tring)
Debug.WriteLine ("Message = " + e.Message)
Debug.WriteLine ("FullText = " + e.ToString())
Else
Debug.WriteLine ("Exception = " + o.GetType().ToS tring)
Debug.WriteLine ("FullText = " + o.ToString())
End If
MsgBox(e.Messag e)
End Sub

End Module

'----------------------------------------------
'Here is the class that the textbox will be
'bound to. Note how it throws an error if you
'try to change the Name property to "Bob"
'----------------------------------------------
Public Class XClass
Private myName As String = String.Empty
Public Property Name() As String
Get
Return myName
End Get
Set(ByVal Value As String)
If Value = "Bob" Then
Throw New Exception("Name Cannot Be Bob")
Else
myName = value
End If
End Set
End Property
End Class

*************** *************** *************** ************
2. Now add a form to the project with the following code:
*************** *************** *************** ************
Public Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows. Forms.TextBox
Friend WithEvents TextBox2 As System.Windows. Forms.TextBox
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.TextBox1 = New System.Windows. Forms.TextBox
Me.TextBox2 = New System.Windows. Forms.TextBox
Me.SuspendLayou t()
'
'TextBox1
'
Me.TextBox1.Loc ation = New System.Drawing. Point(24, 48)
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Siz e = New System.Drawing. Size(248, 20)
Me.TextBox1.Tab Index = 0
Me.TextBox1.Tex t = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Loc ation = New System.Drawing. Point(24, 80)
Me.TextBox2.Nam e = "TextBox2"
Me.TextBox2.Siz e = New System.Drawing. Size(248, 20)
Me.TextBox2.Tab Index = 1
Me.TextBox2.Tex t = "TextBox2"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 181)
Me.Controls.Add (Me.TextBox2)
Me.Controls.Add (Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private myXclass As New XClass
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
TextBox1.DataBi ndings.Add("Tex t", myXclass, "Name")
End Sub
End Class
*************** *************** *************** ************
3. Run the project and set textbox 1 to "Roger" note that you can still
tab to textbox2 or close the form...

4. Now change textbox1 to "Bob" -- you can no longer tab to another
control nor can you close the form... and despite all the error handling
in the program, you can't catch the error!

*************** *************** *************** ************
SO... WHO CAN FIGURE THIS ONE OUT??? BIG PRIZES, AWARDS, FAME AND GLORY
AWAIT YOU... (OR AT LEAST A BIG THANK YOU FROM ME, IF NOTHING ELSE!)
GOOD LUCK, AND THANK YOU IN ADVANCE!!!
*************** *************** *************** ************
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #5
Three ideas, three misses... but I thank you all for your input. I
agree with the first response, that the reason I am not able to catch
this error is because the binding mechanism is set up to ignore all
errors. Even though I am throwing the error in the SET method, the set
method is being called by the inner code (framework) somewhere that has
an exception handler that ignores all errors. I'd love to hear from
someone at Microsoft on this.

Of course if anyone else has some valuable input or ideas, keep them
coming... the GRAND PRIZE is still up for grabs, and I think People
Magazine is looking to cover this story and might even put your picture
on the cover of next month's magazine if you solve it! ;-)

--Zorpie

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #6
Three ideas, three misses... but I thank you all for your input. I
agree with the first response, that the reason I am not able to catch
this error is because the binding mechanism is set up to ignore all
errors. Even though I am throwing the error in the SET method, the set
method is being called by the inner code (framework) somewhere that has
an exception handler that ignores all errors. I'd love to hear from
someone at Microsoft on this.

Of course if anyone else has some valuable input or ideas, keep them
coming... the GRAND PRIZE is still up for grabs, and I think People
Magazine is looking to cover this story and might even put your picture
on the cover of next month's magazine if you solve it! ;-)

--Zorpie

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #7
JD
Think validation.

Test1: Take out the throwing of the "Bob" exception, handle the same
textbox's validation event, set the CancelEventArgs Cancel property to true.
Whats the behavior that you get? The same as throwing the "Bob" exception.

Test2: Set the textbox focus causevalidation to false, works like a charm.

JD


"ZorpiedoMa n" <No********@Bea tles.com> wrote in message
news:e%******** ********@TK2MSF TNGP09.phx.gbl. ..
Well, I'm still wondering around in the "land of the lost exception"...
It seems that controls that are bound to a class and the class throws an
error in the SET method of the bound member, the exception cannot be
caught. I have wrapped my entire application in all the global
exception handlers I can find, and still to no avail. In fact all the
Try/Catches and Exception event handlers are worthless...

Put on your advanced thinking caps, and help me solve this one, please!

To recreate the problem:
*************** *************** *************** ************
1. In a new WindowsForm project, add Module1 as follows:
*************** *************** *************** ************

'----------------------------------------------
'This module is right out of the text book for
'handling unhandled exceptions:
'----------------------------------------------
Module Module1
Public Sub main()
Try
SubMain()
Catch ex As Exception
HandleUnhandled Exception(ex)
End Try
End Sub
Private Sub SubMain()
AddHandler AppDomain.Curre ntDomain.Unhand ledException, AddressOf
OnUnhandledExce ption
AddHandler Application.Thr eadException, AddressOf
OnGuiUnhandedEx ception
Application.Run (New Form1)
End Sub

Private Sub OnUnhandledExce ption(ByVal sender As Object, ByVal e As
UnhandledExcept ionEventArgs)
HandleUnhandled Exception(e.Exc eptionObject)
End Sub
Private Sub OnGuiUnhandedEx ception(ByVal sender As Object, ByVal e
As System.Threadin g.ThreadExcepti onEventArgs)
HandleUnhandled Exception(e.Exc eption)
End Sub

Private Sub HandleUnhandled Exception(ByVal o As Object)
Dim e As Exception = DirectCast(o, Exception)
If Not e Is Nothing Then
Debug.WriteLine ("Exception = " + e.GetType().ToS tring)
Debug.WriteLine ("Message = " + e.Message)
Debug.WriteLine ("FullText = " + e.ToString())
Else
Debug.WriteLine ("Exception = " + o.GetType().ToS tring)
Debug.WriteLine ("FullText = " + o.ToString())
End If
MsgBox(e.Messag e)
End Sub

End Module

'----------------------------------------------
'Here is the class that the textbox will be
'bound to. Note how it throws an error if you
'try to change the Name property to "Bob"
'----------------------------------------------
Public Class XClass
Private myName As String = String.Empty
Public Property Name() As String
Get
Return myName
End Get
Set(ByVal Value As String)
If Value = "Bob" Then
Throw New Exception("Name Cannot Be Bob")
Else
myName = value
End If
End Set
End Property
End Class

*************** *************** *************** ************
2. Now add a form to the project with the following code:
*************** *************** *************** ************
Public Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows. Forms.TextBox
Friend WithEvents TextBox2 As System.Windows. Forms.TextBox
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.TextBox1 = New System.Windows. Forms.TextBox
Me.TextBox2 = New System.Windows. Forms.TextBox
Me.SuspendLayou t()
'
'TextBox1
'
Me.TextBox1.Loc ation = New System.Drawing. Point(24, 48)
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Siz e = New System.Drawing. Size(248, 20)
Me.TextBox1.Tab Index = 0
Me.TextBox1.Tex t = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Loc ation = New System.Drawing. Point(24, 80)
Me.TextBox2.Nam e = "TextBox2"
Me.TextBox2.Siz e = New System.Drawing. Size(248, 20)
Me.TextBox2.Tab Index = 1
Me.TextBox2.Tex t = "TextBox2"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 181)
Me.Controls.Add (Me.TextBox2)
Me.Controls.Add (Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private myXclass As New XClass
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
TextBox1.DataBi ndings.Add("Tex t", myXclass, "Name")
End Sub
End Class
*************** *************** *************** ************
3. Run the project and set textbox 1 to "Roger" note that you can still
tab to textbox2 or close the form...

4. Now change textbox1 to "Bob" -- you can no longer tab to another
control nor can you close the form... and despite all the error handling
in the program, you can't catch the error!

*************** *************** *************** ************
SO... WHO CAN FIGURE THIS ONE OUT??? BIG PRIZES, AWARDS, FAME AND GLORY
AWAIT YOU... (OR AT LEAST A BIG THANK YOU FROM ME, IF NOTHING ELSE!)
GOOD LUCK, AND THANK YOU IN ADVANCE!!!
*************** *************** *************** ************
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #8

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

Similar topics

6
5489
by: Rune | last post by:
Hi, I've written a very simple 'kill-server' to help me shut down processes through Telnet or HTTP. The kill-server is a function and is launched as a thread. I use the module socket.py on Python v2.3 (Windows) I can use telnet host:port and enter the secret killword or use a broser with http://host:port/secret_killword The 'kill-server' validates the secret_killword and writes a file
0
2476
by: seth | last post by:
Last week I encountered an AttributeError in my unit tests that I wasn'table to catch with an "except AttributeError" statement. The problem stemmed from a class that raised an error inside __init__and defined a __del__ method to clean up resources. I then discovered asimilar problem in the shelve module. This led me to two importantdiscoveries: 1. Attributes defined in __init__ after an error is raised will not be apart of the...
4
2766
by: Nicolas Fleury | last post by:
Hi, I've made a small utility to re-raise an exception with the same stack as before with additional information in it. Since I want to keep the same exception type and that some types have very specific constructors (which take, for example, more than one parameter), the only safe way I have found to made it is by hacking the str representation: import sys
1
4231
by: Old Wolf | last post by:
1. What is the difference between #include <stdexcept> and #include <exception> ? 2. Is there a list somewhere of what each standard exception is used for? either to throw them, or throw user-defined exceptions derived from them? (for example I have been deriving mine from std::bad_alloc if there was a memory problem, or std::bad_exception if there was some other problem) 3. Is it a good idea to make all user-defined exceptions derive...
44
4231
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level user tasks should always be included in a try/catch block that actually handles any exceptions that occur (log the exception, display a message box, etc.). 2. Low-level operations that are used to carry out the high level tasks
7
3160
by: cs | last post by:
We have some code that walks the process tree on windows xp. It uses the process class in system diagnostic as well as some dllimport calls to kernel32.dll and ntdll.dll We also have some code that talks on terminal services virtual channels using wtsapi32.dll What we have noticed is that after calling those methods several times per minute in some cases or at least lots of times per hour all day long will end up giving a "application...
3
2511
by: JohnDeHope3 | last post by:
First let me say that I understand that Asp.Net wraps my exception in an HttpUnhandledException. I have found a lot of discussion about that on the web, which was informative, but not helpful. Let me explain how my question is different. Second, let me say that I have two questions. One is an ASP.Net related question. The other is a general System.Exception question. They are related but also individual. Okay here is my problem...
1
4045
by: paul.hine | last post by:
Hello, I maintain an application that pulls data from a web service and writes it to an Excel sheet. Originally, the app used OleDb to write the Excel. Exports ran fine except that some text fields were truncated due to the 255 character limit of the Jet Excel driver. To overcome this limit, I decided to just generate CSV directly. This is where my trouble began. First I tried the StreamWriter class, implemented as per the "How to:
2
6994
by: Darko Miletic | last post by:
Recently I wrote a dll in c++ and to simplify the distribution I decided to link with multithreaded static library (/MT or /MTd option). In debug everything works fine but in release I get this: parseMetadata.obj : error LNK2001: unresolved external symbol "public: __thiscall std::exception::exception(void)" (??0exception@std@@QAE@XZ) 2>libcpmt.lib(string.obj) : error LNK2001: unresolved external symbol "public: __thiscall...
0
10453
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10172
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9050
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.