473,508 Members | 2,040 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
HandleUnhandledException(ex)
End Try
End Sub
Private Sub SubMain()
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf
OnUnhandledException
AddHandler Application.ThreadException, AddressOf
OnGuiUnhandedException
Application.Run(New Form1)
End Sub

Private Sub OnUnhandledException(ByVal sender As Object, ByVal e As
UnhandledExceptionEventArgs)
HandleUnhandledException(e.ExceptionObject)
End Sub
Private Sub OnGuiUnhandedException(ByVal sender As Object, ByVal e
As System.Threading.ThreadExceptionEventArgs)
HandleUnhandledException(e.Exception)
End Sub

Private Sub HandleUnhandledException(ByVal o As Object)
Dim e As Exception = DirectCast(o, Exception)
If Not e Is Nothing Then
Debug.WriteLine("Exception = " + e.GetType().ToString)
Debug.WriteLine("Message = " + e.Message)
Debug.WriteLine("FullText = " + e.ToString())
Else
Debug.WriteLine("Exception = " + o.GetType().ToString)
Debug.WriteLine("FullText = " + o.ToString())
End If
MsgBox(e.Message)
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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(24, 48)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(248, 20)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(24, 80)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(248, 20)
Me.TextBox2.TabIndex = 1
Me.TextBox2.Text = "TextBox2"
'
'Form1
'
Me.AutoScaleBaseSize = 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.DataBindings.Add("Text", 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 1697
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.Add()) 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

"ZorpiedoMan" <No********@Beatles.com> wrote in message
news:e%****************@TK2MSFTNGP09.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
HandleUnhandledException(ex)
End Try
End Sub
Private Sub SubMain()
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf
OnUnhandledException
AddHandler Application.ThreadException, AddressOf
OnGuiUnhandedException
Application.Run(New Form1)
End Sub

Private Sub OnUnhandledException(ByVal sender As Object, ByVal e As
UnhandledExceptionEventArgs)
HandleUnhandledException(e.ExceptionObject)
End Sub
Private Sub OnGuiUnhandedException(ByVal sender As Object, ByVal e
As System.Threading.ThreadExceptionEventArgs)
HandleUnhandledException(e.Exception)
End Sub

Private Sub HandleUnhandledException(ByVal o As Object)
Dim e As Exception = DirectCast(o, Exception)
If Not e Is Nothing Then
Debug.WriteLine("Exception = " + e.GetType().ToString)
Debug.WriteLine("Message = " + e.Message)
Debug.WriteLine("FullText = " + e.ToString())
Else
Debug.WriteLine("Exception = " + o.GetType().ToString)
Debug.WriteLine("FullText = " + o.ToString())
End If
MsgBox(e.Message)
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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(24, 48)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(248, 20)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(24, 80)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(248, 20)
Me.TextBox2.TabIndex = 1
Me.TextBox2.Text = "TextBox2"
'
'Form1
'
Me.AutoScaleBaseSize = 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.DataBindings.Add("Text", 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.Exception is thrown when ever an error is thrown. The
exception class inherits from system.applicationexception. They are thrown
when a non-fatal application occurs. Try catching a system.exception
instead.

Try
SubMain()
Catch ex As System.Exception
HandleUnhandledException(ex)
End Try

Ken
-------------------------
"ZorpiedoMan" <No********@Beatles.com> wrote in message
news:e%****************@TK2MSFTNGP09.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
HandleUnhandledException(ex)
End Try
End Sub
Private Sub SubMain()
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf
OnUnhandledException
AddHandler Application.ThreadException, AddressOf
OnGuiUnhandedException
Application.Run(New Form1)
End Sub

Private Sub OnUnhandledException(ByVal sender As Object, ByVal e As
UnhandledExceptionEventArgs)
HandleUnhandledException(e.ExceptionObject)
End Sub
Private Sub OnGuiUnhandedException(ByVal sender As Object, ByVal e
As System.Threading.ThreadExceptionEventArgs)
HandleUnhandledException(e.Exception)
End Sub

Private Sub HandleUnhandledException(ByVal o As Object)
Dim e As Exception = DirectCast(o, Exception)
If Not e Is Nothing Then
Debug.WriteLine("Exception = " + e.GetType().ToString)
Debug.WriteLine("Message = " + e.Message)
Debug.WriteLine("FullText = " + e.ToString())
Else
Debug.WriteLine("Exception = " + o.GetType().ToString)
Debug.WriteLine("FullText = " + o.ToString())
End If
MsgBox(e.Message)
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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(24, 48)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(248, 20)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(24, 80)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(248, 20)
Me.TextBox2.TabIndex = 1
Me.TextBox2.Text = "TextBox2"
'
'Form1
'
Me.AutoScaleBaseSize = 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.DataBindings.Add("Text", 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.Exception is thrown when ever an error is thrown. The
exception class inherits from system.applicationexception. They are thrown
when a non-fatal application occurs. Try catching a system.exception
instead.

Try
SubMain()
Catch ex As System.Exception
HandleUnhandledException(ex)
End Try

Ken
-------------------------
"ZorpiedoMan" <No********@Beatles.com> wrote in message
news:e%****************@TK2MSFTNGP09.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
HandleUnhandledException(ex)
End Try
End Sub
Private Sub SubMain()
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf
OnUnhandledException
AddHandler Application.ThreadException, AddressOf
OnGuiUnhandedException
Application.Run(New Form1)
End Sub

Private Sub OnUnhandledException(ByVal sender As Object, ByVal e As
UnhandledExceptionEventArgs)
HandleUnhandledException(e.ExceptionObject)
End Sub
Private Sub OnGuiUnhandedException(ByVal sender As Object, ByVal e
As System.Threading.ThreadExceptionEventArgs)
HandleUnhandledException(e.Exception)
End Sub

Private Sub HandleUnhandledException(ByVal o As Object)
Dim e As Exception = DirectCast(o, Exception)
If Not e Is Nothing Then
Debug.WriteLine("Exception = " + e.GetType().ToString)
Debug.WriteLine("Message = " + e.Message)
Debug.WriteLine("FullText = " + e.ToString())
Else
Debug.WriteLine("Exception = " + o.GetType().ToString)
Debug.WriteLine("FullText = " + o.ToString())
End If
MsgBox(e.Message)
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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(24, 48)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(248, 20)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(24, 80)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(248, 20)
Me.TextBox2.TabIndex = 1
Me.TextBox2.Text = "TextBox2"
'
'Form1
'
Me.AutoScaleBaseSize = 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.DataBindings.Add("Text", 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


"ZorpiedoMan" <No********@Beatles.com> wrote in message
news:e%****************@TK2MSFTNGP09.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
HandleUnhandledException(ex)
End Try
End Sub
Private Sub SubMain()
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf
OnUnhandledException
AddHandler Application.ThreadException, AddressOf
OnGuiUnhandedException
Application.Run(New Form1)
End Sub

Private Sub OnUnhandledException(ByVal sender As Object, ByVal e As
UnhandledExceptionEventArgs)
HandleUnhandledException(e.ExceptionObject)
End Sub
Private Sub OnGuiUnhandedException(ByVal sender As Object, ByVal e
As System.Threading.ThreadExceptionEventArgs)
HandleUnhandledException(e.Exception)
End Sub

Private Sub HandleUnhandledException(ByVal o As Object)
Dim e As Exception = DirectCast(o, Exception)
If Not e Is Nothing Then
Debug.WriteLine("Exception = " + e.GetType().ToString)
Debug.WriteLine("Message = " + e.Message)
Debug.WriteLine("FullText = " + e.ToString())
Else
Debug.WriteLine("Exception = " + o.GetType().ToString)
Debug.WriteLine("FullText = " + o.ToString())
End If
MsgBox(e.Message)
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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(24, 48)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(248, 20)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(24, 80)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(248, 20)
Me.TextBox2.TabIndex = 1
Me.TextBox2.Text = "TextBox2"
'
'Form1
'
Me.AutoScaleBaseSize = 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.DataBindings.Add("Text", 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
5472
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...
0
2447
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...
4
2744
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...
1
4197
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...
44
4162
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...
7
3135
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...
3
2499
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...
1
4020
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...
2
6957
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: ...
0
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
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...
1
7049
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...
1
5055
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...
0
4709
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...
0
3199
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...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1561
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 ...
0
422
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...

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.