473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Custom Error Handling

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
:o( 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.
Nov 21 '05 #1
6 1557
Hiya

I have just noticed that my Custom Exception is being added in to an
Exception Object as the Inner Exception. Eg. Ex.InnerException =
MyCustomException

How woud I get my Exception to be the top most Exception? So Ex =
MyCustomException.

Regards,
Steve.

"Steve Amey" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message
news:eg**************@TK2MSFTNGP14.phx.gbl...
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
:o( 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.

Nov 21 '05 #2
Steve,
Which version of VS.NET? With VS.NET 2003 I am not able to reproduce your
problem.

What exception are you seeing instead of MyCustomException?

I would recommend including the exception you caught as an inner exception
when you throw a new MyCustomException.

Hope this helps
Jay

"Steve Amey" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message
news:eg**************@TK2MSFTNGP14.phx.gbl...
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
:o( 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.

Nov 21 '05 #3
Hi Jay

I am using 2003, but it appears to be working now! I've lost count the
amount of times something doesn't work but suddenly does the next day :o)

I am having 1 more difficulty though, when I populate my custom exception I
set the properties such as Message, InnerException etc... but when the
exception is shown the message simply reads 'Error in the application'. When
I step through the code I set the properties, and I can see the module level
variables change, but the property doesn't. The Properties have to be
declared as Shadows, is this the reason the Message is not being displayed
correctly?

Here is the code for my Class:
-----------------------------------------------
Public Class MyCustomException
Inherits ApplicationException

Public Sub New(ByVal Ex As Exception)
With Me
..InnerException = Ex
..Message = Ex.Message.ToString
..Source = Ex.Source.ToString
..StackTrace = Ex.StackTrace.ToString
..TargetSite = Ex.TargetSite
..HelpLink = Ex.HelpLink
End With
End Sub

Public Sub New(ByVal Ex As Exception, ByVal dataSet As DataSet)
With Me
..InnerException = Ex
..Message = Ex.Message.ToString
..Source = Ex.Source.ToString
..StackTrace = Ex.StackTrace.ToString
..TargetSite = Ex.TargetSite
..HelpLink = Ex.HelpLink
..DataSet = dataSet
End With
End Sub

Public Shadows Property InnerException() As Exception
Get
Return m_InnerException
End Get
Set(ByVal Value As Exception)
m_InnerException = Value
End Set
End Property

Public Overrides Property Source() As String
Get
Return m_Source
End Get
Set(ByVal Value As String)
m_Source = Value
End Set
End Property

Public Shadows Property Message() As String
Get
Return m_Message
End Get
Set(ByVal Value As String)
m_Message = Value
End Set
End Property

Public Shadows Property TargetSite() As Reflection.MethodBase
Get
Return m_TargetSite
End Get
Set(ByVal Value As Reflection.MethodBase)
m_TargetSite = Value
End Set
End Property

Public Shadows Property StackTrace() As String
Get
Return m_StackTrace
End Get
Set(ByVal Value As String)
m_StackTrace = Value
End Set
End Property

Public Shadows Property HelpLink() As String
Get
Return m_HelpLink
End Get
Set(ByVal Value As String)
m_HelpLink = Value
End Set
End Property

Public Property DataSet() As DataSet
Get
Return m_oDataSet
End Get
Set(ByVal Value As DataSet)
m_oDataSet = Value
End Set
End Property

End Class
-----------------------------------------------------

So when I read the MyCustomException.Message property, it doesn't return the
value in m_Message but returns the text I described above.

Regards,
Steve

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eS**************@TK2MSFTNGP14.phx.gbl...
Steve,
Which version of VS.NET? With VS.NET 2003 I am not able to reproduce your
problem.

What exception are you seeing instead of MyCustomException?

I would recommend including the exception you caught as an inner exception
when you throw a new MyCustomException.

Hope this helps
Jay

"Steve Amey" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message
news:eg**************@TK2MSFTNGP14.phx.gbl...
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
:o( 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.


Nov 21 '05 #4
Steve,
The Properties have to be
declared as Shadows, is this the reason the Message is not being displayed
correctly? Correct.

You should not Shadow base class members! Shadows is used primarily for
version control. For example: You release version one of your
MyCustomException with a specific method, MS release .NET 2.0 with the same
method in System.ApplicationException, Shadows is used in this case to allow
you to continue using your method, while the base class can use its own
version of the method.

I was suggesting you pass the exception you caught to the base constructor:

Optionally I would allow users of the exception to specify a Message, and
not specify the innerException, something like:

Public Class MyCustomException
Inherits ApplicationException

Private ReadOnly m_dataSet As DataSet

Public Sub New()
MyClass.New(Nothing, Nothing, Nothing)
End Sub

Public Sub New(ByVal message As String)
MyClass.New(message, Nothing, Nothing)
End Sub

Public Sub New(ByVal innerException As Exception)
MyClass.New(Nothing, innerException, Nothing)
End Sub

Public Sub New(ByVal dataSet As DataSet)
MyClass.New(Nothing, Nothing, dataSet)
End Sub

Public Sub New(ByVal message As String, ByVal innerException As
Exception)
MyClass.New(message, innerException, Nothing)
End Sub

Public Sub New(ByVal message As String, ByVal dataSet As DataSet)
MyClass.New(message, Nothing, dataSet)
End Sub

Public Sub New(ByVal innerException As Exception, ByVal dataSet As
DataSet)
MyClass.New(Nothing, innerException, dataSet)
End Sub

Public Sub New(ByVal message As String, ByVal innerException As
Exception, ByVal dataSet As DataSet)
MyBase.New(message, innerException)
m_dataSet = dataSet
End Sub

Public ReadOnly Property DataSet() As DataSet
Get
Return m_dataSet
End Get
End Property

End Class

NOTE: The MyClass.New allows you to call another constructor on the same
class, while MyBase.New allows you to call a base constructor. I chain all
the constructors into one common constructor, then this common constructor
calls the base constructor. I do not show the special constructor required
for serialization.

The following article provides some good information on creating custom
Exception classes.

http://msdn.microsoft.com/library/de...rp08162001.asp

The example are in C#, however they should be easy enough to convert to
VB.NET.

Hope this helps
Jay
"Steve Amey" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... Hi Jay

I am using 2003, but it appears to be working now! I've lost count the
amount of times something doesn't work but suddenly does the next day :o)

I am having 1 more difficulty though, when I populate my custom exception
I
set the properties such as Message, InnerException etc... but when the
exception is shown the message simply reads 'Error in the application'.
When
I step through the code I set the properties, and I can see the module
level
variables change, but the property doesn't. The Properties have to be
declared as Shadows, is this the reason the Message is not being displayed
correctly?

Here is the code for my Class:
-----------------------------------------------
Public Class MyCustomException
Inherits ApplicationException

Public Sub New(ByVal Ex As Exception)
With Me
.InnerException = Ex
.Message = Ex.Message.ToString
.Source = Ex.Source.ToString
.StackTrace = Ex.StackTrace.ToString
.TargetSite = Ex.TargetSite
.HelpLink = Ex.HelpLink
End With
End Sub

Public Sub New(ByVal Ex As Exception, ByVal dataSet As DataSet)
With Me
.InnerException = Ex
.Message = Ex.Message.ToString
.Source = Ex.Source.ToString
.StackTrace = Ex.StackTrace.ToString
.TargetSite = Ex.TargetSite
.HelpLink = Ex.HelpLink
.DataSet = dataSet
End With
End Sub

Public Shadows Property InnerException() As Exception
Get
Return m_InnerException
End Get
Set(ByVal Value As Exception)
m_InnerException = Value
End Set
End Property

Public Overrides Property Source() As String
Get
Return m_Source
End Get
Set(ByVal Value As String)
m_Source = Value
End Set
End Property

Public Shadows Property Message() As String
Get
Return m_Message
End Get
Set(ByVal Value As String)
m_Message = Value
End Set
End Property

Public Shadows Property TargetSite() As Reflection.MethodBase
Get
Return m_TargetSite
End Get
Set(ByVal Value As Reflection.MethodBase)
m_TargetSite = Value
End Set
End Property

Public Shadows Property StackTrace() As String
Get
Return m_StackTrace
End Get
Set(ByVal Value As String)
m_StackTrace = Value
End Set
End Property

Public Shadows Property HelpLink() As String
Get
Return m_HelpLink
End Get
Set(ByVal Value As String)
m_HelpLink = Value
End Set
End Property

Public Property DataSet() As DataSet
Get
Return m_oDataSet
End Get
Set(ByVal Value As DataSet)
m_oDataSet = Value
End Set
End Property

End Class
-----------------------------------------------------

So when I read the MyCustomException.Message property, it doesn't return
the
value in m_Message but returns the text I described above.

Regards,
Steve

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eS**************@TK2MSFTNGP14.phx.gbl...
Steve,
Which version of VS.NET? With VS.NET 2003 I am not able to reproduce your
problem.

What exception are you seeing instead of MyCustomException?

I would recommend including the exception you caught as an inner
exception
when you throw a new MyCustomException.

Hope this helps
Jay

"Steve Amey" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message
news:eg**************@TK2MSFTNGP14.phx.gbl...
> 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
> :o( 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.
>
>



Nov 21 '05 #5
Steve,
I should add, you can override either (or both) the Exception.Message
property & Exception.ToString, if you want to include details from the
dataset, when Exception.Message is displayed or Exception.ToString is used.

Normally I use Exception.Message when I am displaying the exception to the
user, while I use Exception.ToString when I am logging the exception in my
Global Exception Handler.

Hope this helps
Jay
"Steve Amey" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi Jay

I am using 2003, but it appears to be working now! I've lost count the
amount of times something doesn't work but suddenly does the next day :o)

I am having 1 more difficulty though, when I populate my custom exception
I
set the properties such as Message, InnerException etc... but when the
exception is shown the message simply reads 'Error in the application'.
When
I step through the code I set the properties, and I can see the module
level
variables change, but the property doesn't. The Properties have to be
declared as Shadows, is this the reason the Message is not being displayed
correctly?

Here is the code for my Class:
-----------------------------------------------
Public Class MyCustomException
Inherits ApplicationException

Public Sub New(ByVal Ex As Exception)
With Me
.InnerException = Ex
.Message = Ex.Message.ToString
.Source = Ex.Source.ToString
.StackTrace = Ex.StackTrace.ToString
.TargetSite = Ex.TargetSite
.HelpLink = Ex.HelpLink
End With
End Sub

Public Sub New(ByVal Ex As Exception, ByVal dataSet As DataSet)
With Me
.InnerException = Ex
.Message = Ex.Message.ToString
.Source = Ex.Source.ToString
.StackTrace = Ex.StackTrace.ToString
.TargetSite = Ex.TargetSite
.HelpLink = Ex.HelpLink
.DataSet = dataSet
End With
End Sub

Public Shadows Property InnerException() As Exception
Get
Return m_InnerException
End Get
Set(ByVal Value As Exception)
m_InnerException = Value
End Set
End Property

Public Overrides Property Source() As String
Get
Return m_Source
End Get
Set(ByVal Value As String)
m_Source = Value
End Set
End Property

Public Shadows Property Message() As String
Get
Return m_Message
End Get
Set(ByVal Value As String)
m_Message = Value
End Set
End Property

Public Shadows Property TargetSite() As Reflection.MethodBase
Get
Return m_TargetSite
End Get
Set(ByVal Value As Reflection.MethodBase)
m_TargetSite = Value
End Set
End Property

Public Shadows Property StackTrace() As String
Get
Return m_StackTrace
End Get
Set(ByVal Value As String)
m_StackTrace = Value
End Set
End Property

Public Shadows Property HelpLink() As String
Get
Return m_HelpLink
End Get
Set(ByVal Value As String)
m_HelpLink = Value
End Set
End Property

Public Property DataSet() As DataSet
Get
Return m_oDataSet
End Get
Set(ByVal Value As DataSet)
m_oDataSet = Value
End Set
End Property

End Class
-----------------------------------------------------

So when I read the MyCustomException.Message property, it doesn't return
the
value in m_Message but returns the text I described above.

Regards,
Steve

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eS**************@TK2MSFTNGP14.phx.gbl...
Steve,
Which version of VS.NET? With VS.NET 2003 I am not able to reproduce your
problem.

What exception are you seeing instead of MyCustomException?

I would recommend including the exception you caught as an inner
exception
when you throw a new MyCustomException.

Hope this helps
Jay

"Steve Amey" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message
news:eg**************@TK2MSFTNGP14.phx.gbl...
> 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
> :o( 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.
>
>



Nov 21 '05 #6
Hi Jay

Thank you very much for your help, it's much appreciated!

Kind Regards,
Steve

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eg*************@TK2MSFTNGP11.phx.gbl...
Steve,
I should add, you can override either (or both) the Exception.Message
property & Exception.ToString, if you want to include details from the
dataset, when Exception.Message is displayed or Exception.ToString is used.
Normally I use Exception.Message when I am displaying the exception to the
user, while I use Exception.ToString when I am logging the exception in my
Global Exception Handler.

Hope this helps
Jay
"Steve Amey" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi Jay

I am using 2003, but it appears to be working now! I've lost count the
amount of times something doesn't work but suddenly does the next day :o)
I am having 1 more difficulty though, when I populate my custom exception I
set the properties such as Message, InnerException etc... but when the
exception is shown the message simply reads 'Error in the application'.
When
I step through the code I set the properties, and I can see the module
level
variables change, but the property doesn't. The Properties have to be
declared as Shadows, is this the reason the Message is not being displayed correctly?

Here is the code for my Class:
-----------------------------------------------
Public Class MyCustomException
Inherits ApplicationException

Public Sub New(ByVal Ex As Exception)
With Me
.InnerException = Ex
.Message = Ex.Message.ToString
.Source = Ex.Source.ToString
.StackTrace = Ex.StackTrace.ToString
.TargetSite = Ex.TargetSite
.HelpLink = Ex.HelpLink
End With
End Sub

Public Sub New(ByVal Ex As Exception, ByVal dataSet As DataSet)
With Me
.InnerException = Ex
.Message = Ex.Message.ToString
.Source = Ex.Source.ToString
.StackTrace = Ex.StackTrace.ToString
.TargetSite = Ex.TargetSite
.HelpLink = Ex.HelpLink
.DataSet = dataSet
End With
End Sub

Public Shadows Property InnerException() As Exception
Get
Return m_InnerException
End Get
Set(ByVal Value As Exception)
m_InnerException = Value
End Set
End Property

Public Overrides Property Source() As String
Get
Return m_Source
End Get
Set(ByVal Value As String)
m_Source = Value
End Set
End Property

Public Shadows Property Message() As String
Get
Return m_Message
End Get
Set(ByVal Value As String)
m_Message = Value
End Set
End Property

Public Shadows Property TargetSite() As Reflection.MethodBase
Get
Return m_TargetSite
End Get
Set(ByVal Value As Reflection.MethodBase)
m_TargetSite = Value
End Set
End Property

Public Shadows Property StackTrace() As String
Get
Return m_StackTrace
End Get
Set(ByVal Value As String)
m_StackTrace = Value
End Set
End Property

Public Shadows Property HelpLink() As String
Get
Return m_HelpLink
End Get
Set(ByVal Value As String)
m_HelpLink = Value
End Set
End Property

Public Property DataSet() As DataSet
Get
Return m_oDataSet
End Get
Set(ByVal Value As DataSet)
m_oDataSet = Value
End Set
End Property

End Class
-----------------------------------------------------

So when I read the MyCustomException.Message property, it doesn't return
the
value in m_Message but returns the text I described above.

Regards,
Steve

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:eS**************@TK2MSFTNGP14.phx.gbl...
Steve,
Which version of VS.NET? With VS.NET 2003 I am not able to reproduce your problem.

What exception are you seeing instead of MyCustomException?

I would recommend including the exception you caught as an inner
exception
when you throw a new MyCustomException.

Hope this helps
Jay

"Steve Amey" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message
news:eg**************@TK2MSFTNGP14.phx.gbl...
> 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 > :o( 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.
>
>



Nov 21 '05 #7

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

Similar topics

2
by: Sean Mullaly | last post by:
I have a custom Access menu with sub-menus and sub-sub-menus. (220 items). Right now I have created 220 Functions and attached each individual Function to the specific OnAction property. The...
0
by: Rhys666 | last post by:
OK, an issue I've come across before, but never found a cause for or resolution of, has decided to become the bane of my life again with ASP.Net Custom Error Pages. Basically, my web application...
3
by: Mr Newbie | last post by:
I'm testing error handling configurations and having some trouble. I created a WebForm called. ErrDefault.aspx and I am trying to use the Page error attribute to force the redirection to a custom...
15
by: bill salkin | last post by:
I'd like to create a custom error handler like this in VB.NET: .... try ... Throw ("Lender Name not in table") .... catch ("Lender Name not in table")
4
by: Paul Wilson | last post by:
I want to use Err.Raise() method to raise my own exceptions. Is this the right way of raising my own exceptions ? (i think this is the only way). What is the Error number i can safely use,...
1
by: serge calderara | last post by:
dear all, i am a bit confused on the way custom error are handling and occurs. First of all I have understand that customer error is used to defined more user friendly message to my end user and...
5
by: jegec | last post by:
Hi all! Brief subject: I have to develop an ASP-based application, and build also a specific error handling ASP. After that I had set the virtual directory Custom Error 500;100 to new ASP -...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.