473,722 Members | 2,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 MyCustomExcepti on
'// 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.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
Try
'// Perform some stuff that might encounter an error
Catch Ex As Exception
Throw New MyCustomExcepti on '// 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 MyCustomExcepti on
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 1587
Hiya

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

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

Regards,
Steve.

"Steve Amey" <stevea@centuri on-ms_RemoveThis_. co.uk> wrote in message
news:eg******** ******@TK2MSFTN GP14.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 MyCustomExcepti on
'// 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.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
Try
'// Perform some stuff that might encounter an error
Catch Ex As Exception
Throw New MyCustomExcepti on '// 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 MyCustomExcepti on
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 MyCustomExcepti on?

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

Hope this helps
Jay

"Steve Amey" <stevea@centuri on-ms_RemoveThis_. co.uk> wrote in message
news:eg******** ******@TK2MSFTN GP14.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 MyCustomExcepti on
'// 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.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
Try
'// Perform some stuff that might encounter an error
Catch Ex As Exception
Throw New MyCustomExcepti on '// 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 MyCustomExcepti on
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 MyCustomExcepti on
Inherits ApplicationExce ption

Public Sub New(ByVal Ex As Exception)
With Me
..InnerExceptio n = Ex
..Message = Ex.Message.ToSt ring
..Source = Ex.Source.ToStr ing
..StackTrace = Ex.StackTrace.T oString
..TargetSite = Ex.TargetSite
..HelpLink = Ex.HelpLink
End With
End Sub

Public Sub New(ByVal Ex As Exception, ByVal dataSet As DataSet)
With Me
..InnerExceptio n = Ex
..Message = Ex.Message.ToSt ring
..Source = Ex.Source.ToStr ing
..StackTrace = Ex.StackTrace.T oString
..TargetSite = Ex.TargetSite
..HelpLink = Ex.HelpLink
..DataSet = dataSet
End With
End Sub

Public Shadows Property InnerException( ) As Exception
Get
Return m_InnerExceptio n
End Get
Set(ByVal Value As Exception)
m_InnerExceptio n = 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.Meth odBase
Get
Return m_TargetSite
End Get
Set(ByVal Value As Reflection.Meth odBase)
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 MyCustomExcepti on.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******** ******@TK2MSFTN GP14.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 MyCustomExcepti on?

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

Hope this helps
Jay

"Steve Amey" <stevea@centuri on-ms_RemoveThis_. co.uk> wrote in message
news:eg******** ******@TK2MSFTN GP14.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 MyCustomExcepti on
'// 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.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
Try
'// Perform some stuff that might encounter an error
Catch Ex As Exception
Throw New MyCustomExcepti on '// 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 MyCustomExcepti on 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
MyCustomExcepti on with a specific method, MS release .NET 2.0 with the same
method in System.Applicat ionException, 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 MyCustomExcepti on
Inherits ApplicationExce ption

Private ReadOnly m_dataSet As DataSet

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

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

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

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

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

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

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

Public Sub New(ByVal message As String, ByVal innerException As
Exception, ByVal dataSet As DataSet)
MyBase.New(mess age, 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@centuri on-ms_RemoveThis_. co.uk> wrote in message
news:%2******** ********@TK2MSF TNGP12.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 MyCustomExcepti on
Inherits ApplicationExce ption

Public Sub New(ByVal Ex As Exception)
With Me
.InnerException = Ex
.Message = Ex.Message.ToSt ring
.Source = Ex.Source.ToStr ing
.StackTrace = Ex.StackTrace.T oString
.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.ToSt ring
.Source = Ex.Source.ToStr ing
.StackTrace = Ex.StackTrace.T oString
.TargetSite = Ex.TargetSite
.HelpLink = Ex.HelpLink
.DataSet = dataSet
End With
End Sub

Public Shadows Property InnerException( ) As Exception
Get
Return m_InnerExceptio n
End Get
Set(ByVal Value As Exception)
m_InnerExceptio n = 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.Meth odBase
Get
Return m_TargetSite
End Get
Set(ByVal Value As Reflection.Meth odBase)
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 MyCustomExcepti on.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******** ******@TK2MSFTN GP14.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 MyCustomExcepti on?

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

Hope this helps
Jay

"Steve Amey" <stevea@centuri on-ms_RemoveThis_. co.uk> wrote in message
news:eg******** ******@TK2MSFTN GP14.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 MyCustomExcepti on
> '// 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.
> InitializeCompo nent()
> 'Add any initialization after the InitializeCompo nent() call
> Try
> '// Perform some stuff that might encounter an error
> Catch Ex As Exception
> Throw New MyCustomExcepti on '// 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 MyCustomExcepti on > 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.Messa ge
property & Exception.ToStr ing, if you want to include details from the
dataset, when Exception.Messa ge is displayed or Exception.ToStr ing is used.

Normally I use Exception.Messa ge when I am displaying the exception to the
user, while I use Exception.ToStr ing when I am logging the exception in my
Global Exception Handler.

Hope this helps
Jay
"Steve Amey" <stevea@centuri on-ms_RemoveThis_. co.uk> wrote in message
news:%2******** ********@TK2MSF TNGP12.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 MyCustomExcepti on
Inherits ApplicationExce ption

Public Sub New(ByVal Ex As Exception)
With Me
.InnerException = Ex
.Message = Ex.Message.ToSt ring
.Source = Ex.Source.ToStr ing
.StackTrace = Ex.StackTrace.T oString
.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.ToSt ring
.Source = Ex.Source.ToStr ing
.StackTrace = Ex.StackTrace.T oString
.TargetSite = Ex.TargetSite
.HelpLink = Ex.HelpLink
.DataSet = dataSet
End With
End Sub

Public Shadows Property InnerException( ) As Exception
Get
Return m_InnerExceptio n
End Get
Set(ByVal Value As Exception)
m_InnerExceptio n = 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.Meth odBase
Get
Return m_TargetSite
End Get
Set(ByVal Value As Reflection.Meth odBase)
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 MyCustomExcepti on.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******** ******@TK2MSFTN GP14.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 MyCustomExcepti on?

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

Hope this helps
Jay

"Steve Amey" <stevea@centuri on-ms_RemoveThis_. co.uk> wrote in message
news:eg******** ******@TK2MSFTN GP14.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 MyCustomExcepti on
> '// 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.
> InitializeCompo nent()
> 'Add any initialization after the InitializeCompo nent() call
> Try
> '// Perform some stuff that might encounter an error
> Catch Ex As Exception
> Throw New MyCustomExcepti on '// 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 MyCustomExcepti on > 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******** *****@TK2MSFTNG P11.phx.gbl...
Steve,
I should add, you can override either (or both) the Exception.Messa ge
property & Exception.ToStr ing, if you want to include details from the
dataset, when Exception.Messa ge is displayed or Exception.ToStr ing is used.
Normally I use Exception.Messa ge when I am displaying the exception to the
user, while I use Exception.ToStr ing when I am logging the exception in my
Global Exception Handler.

Hope this helps
Jay
"Steve Amey" <stevea@centuri on-ms_RemoveThis_. co.uk> wrote in message
news:%2******** ********@TK2MSF TNGP12.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 MyCustomExcepti on
Inherits ApplicationExce ption

Public Sub New(ByVal Ex As Exception)
With Me
.InnerException = Ex
.Message = Ex.Message.ToSt ring
.Source = Ex.Source.ToStr ing
.StackTrace = Ex.StackTrace.T oString
.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.ToSt ring
.Source = Ex.Source.ToStr ing
.StackTrace = Ex.StackTrace.T oString
.TargetSite = Ex.TargetSite
.HelpLink = Ex.HelpLink
.DataSet = dataSet
End With
End Sub

Public Shadows Property InnerException( ) As Exception
Get
Return m_InnerExceptio n
End Get
Set(ByVal Value As Exception)
m_InnerExceptio n = 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.Meth odBase
Get
Return m_TargetSite
End Get
Set(ByVal Value As Reflection.Meth odBase)
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 MyCustomExcepti on.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******** ******@TK2MSFTN GP14.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 MyCustomExcepti on?

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

Hope this helps
Jay

"Steve Amey" <stevea@centuri on-ms_RemoveThis_. co.uk> wrote in message
news:eg******** ******@TK2MSFTN GP14.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 MyCustomExcepti on
> '// 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.
> InitializeCompo nent()
> 'Add any initialization after the InitializeCompo nent() call
> Try
> '// Perform some stuff that might encounter an error
> Catch Ex As Exception
> Throw New MyCustomExcepti on '// 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

MyCustomExcepti on
> 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
2287
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 Functions return Text which is the same as the Caption of the sub-sub-menu items. I would like to reference the Custom Popup Caption of these sub-sub-menus and pass it through one Function for input in a form. *** Sent via Developersdex...
0
1675
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 is configured to utilise a custom errors page, in that unhandled exceptions get passed through and the page redirects correctly as per the settings in the web.config file and Global.asax. This works in 95% or so of cases, however... On...
3
2056
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 page, but I only get and unhandled exception page and it does not direct me to my specific page. I'm probably doing something really stupid, but I cant see what . Any Ideas ? - Thanx Mr N --------- DETAILS BELOW -----------
15
2717
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
1834
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, ensuring that it isn't used by ..NET. Ie, can i use -100 as a error number?? Ie, -100, -101,-102... etc. I want to konw if .NET uses negative values as error number? (because i want a specific list of error numbers, to ensure that they are
1
1510
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 that custom errors mask out more details error if the web side is access from the local web server browser right ? If it is so I have read that setting the mode attribute to OFF in web.config
5
7224
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 - and now I have no error handling at all. Even if I reset it to Default! Detailed description:
2
19482
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
2897
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
8863
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
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...
0
9238
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8052
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...
1
6681
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5995
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
4502
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...
1
3207
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

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.