Custom Exception (first "Throw" Takes time)

D

Dan

Hi all!

When I throw my custom Exception class the first time in my code, the
compiler takes a lot of time for find the following catch

EX:

try
Throw New MyCustomException("test")

Catch exx As MyCustomException
MessageBox.Show(exx.Message)
Catch ex As Exception
Me.HandleException(ex)
End Try


Thanks for answers !!

Dan

----------------------------------

Here is my custom exception class :

<Serializable()> _
Public Class MyCustomException : Inherits
System.ApplicationException


'Internal storage of the LayerName custom property
Private m_LayerName As String = ""


'For new exception instance with default property values
Public Sub New()
MyBase.New()
End Sub


'For new exception instance with specified message
Public Sub New(ByVal message As String)
MyBase.New(message)
End Sub


'For new exception instance with specified message and
LayerName
Public Sub New(ByVal message As String, ByVal LayerName As
String)
MyBase.New(message)
m_LayerName = LayerName
End Sub


'For new exception instance with specified message and inner
exception
Public Sub New(ByVal message As String, ByVal innerException As
Exception)
MyBase.New(message, innerException)
End Sub


'For new exception instance with specified message, inner
exception and LayerName
Public Sub New(ByVal message As String, ByVal innerException As
Exception, ByVal LayerName As String)
MyBase.New(message, innerException)
m_LayerName = LayerName
End Sub


'To re-materialize exception and custom property at the
receiving end
Protected Sub New(ByVal info As SerializationInfo, _
ByVal context As StreamingContext)
MyBase.New(info, context)
m_LayerName = info.GetString("LayerName")
End Sub


'To de-materialize exception and custom property at the sending
end
Public Overrides Sub GetObjectData(ByVal info As
SerializationInfo, _
ByVal
context As StreamingContext)
MyBase.GetObjectData(info, context)
info.AddValue("LayerName", m_LayerName)
End Sub


'To add custom property to standard exception message
Public Overrides ReadOnly Property Message() As String
Get
Return MyBase.Message & Environment.NewLine & "Layer
name: " & m_LayerName
End Get
End Property


'LayerName property, to help exception consumers
ReadOnly Property LayerName() As String
Get
LayerName = m_LayerName
End Get
End Property


End Class
 
R

R. MacDonald

Hello, Dan,

I wonder if this is similar to the "problem" that I experience. When
working in debug mode I find a significant delay (measurable in seconds)
between the throw of the exception and the catch, but only for the first
exception. For my application a few seconds is more than a minor
performance hit so I was quite concerned about this.

Happily, it only seems to be a problem when working in the IDE, so it
annoys only me, and not the users.

(Even so, it DOES annoy me. I wouldn't mind if someone could tell us
the "cure" for this.)

Cheers,
Randy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top