S
Steve Amey
Hi all
I want to be able to throw a custom error up the call stack. I have looked
around and it seems as though it's possible, but I can't get it to work
( Below is some sample code.
------------------------------------------------------------
Public Class MainForm
Public Sub Show Form
Try
Dim f As New Form1
f.Show
Catch Ex As MyCustomException
'// Handle the custom exception
Finally
'// Clean-up
End Try
End Sub
End Class
Public Class Form1
Public Sub New()
MyBase.New
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
Try
'// Perform some stuff that might encounter an error
Catch Ex As Exception
Throw New MyCustomException '// I want to throw my exception up to
MainForm
End Try
End Sub
End Class
--------------------------------------------------------------
In the Sub New I will be getting information from a database and also doing
other things, these could result in an Exception. I want to be able to trap
the exception, and then create a new custom exception and have that thrown
up the call stack to the MainForm which would deal with it. If I try to
Throw my custom exception at the moment, the Catch Ex As MyCustomException
does not execute, if I put in a Catch Ex As Exception, then that will
execute.
How do I throw my custom object (which inherits from Exception) and then
catch that object up the call stack.
Regards,
Steve.
I want to be able to throw a custom error up the call stack. I have looked
around and it seems as though it's possible, but I can't get it to work
( Below is some sample code.
------------------------------------------------------------
Public Class MainForm
Public Sub Show Form
Try
Dim f As New Form1
f.Show
Catch Ex As MyCustomException
'// Handle the custom exception
Finally
'// Clean-up
End Try
End Sub
End Class
Public Class Form1
Public Sub New()
MyBase.New
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
Try
'// Perform some stuff that might encounter an error
Catch Ex As Exception
Throw New MyCustomException '// I want to throw my exception up to
MainForm
End Try
End Sub
End Class
--------------------------------------------------------------
In the Sub New I will be getting information from a database and also doing
other things, these could result in an Exception. I want to be able to trap
the exception, and then create a new custom exception and have that thrown
up the call stack to the MainForm which would deal with it. If I try to
Throw my custom exception at the moment, the Catch Ex As MyCustomException
does not execute, if I put in a Catch Ex As Exception, then that will
execute.
How do I throw my custom object (which inherits from Exception) and then
catch that object up the call stack.
Regards,
Steve.