Z
ZorpiedoMan
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!!!
*********************************************************
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!!!
*********************************************************