G
Guest
I am catching an exception in a class derived from ServicedComponent
(original exception being thrown from class the does NOT inherit from
ServicedComponent) and rethrowing a custom exception
(ARSApplicationException), including the original exception in the custom
exception.
If another application receives the exception from the ServicedComponent,
they get the custom exception message, but do not get the custom
ARSApplicationException and do not get access to the Inner Exception.
Instead they get an ApplicationException - which ARSApplicationException
inherits from
Here is the code (which is executed) from the ServicedComponent class:
Try
....
Catch ex As Exception
Throw New ARSApplicationException("The zonal analysis properties could
not be mapped from the database", ex)
End Try
Here is the ARSApplicationException code:
Imports System.Runtime.Serialization
Imports System.Text
<Serializable()> _
Public Class ARSApplicationException
Inherits ApplicationException
Public Sub New(ByVal Message As String)
MyBase.New(Message)
End Sub
Public Sub New(ByVal Message As String, ByVal InnerException As Exception)
MyBase.New(Message, InnerException)
End Sub
Public Sub New(ByVal Info As SerializationInfo, ByVal Context As
StreamingContext)
MyBase.New(Info, Context)
End Sub
Public Overrides Function ToString() As String
Dim objSB As StringBuilder = New StringBuilder(Me.Message)
If Not Me.InnerException Is Nothing Then
objSB.Append(" - ")
objSB.Append("Inner EXception message: " & Me.InnerException.Message)
End If
objSB.Append(vbCrLf & Me.Source)
objSB.Append(vbCrLf & Me.StackTrace)
Return objSB.ToString()
End Function
End Class
Here is the output after catching the exception in the calling application:
System.ApplicationException: The zonal analysis properties could not be
mapped f
rom the database
Server stack trace:
at NZDF.Air.AircraftReview.IZoneAnalysisRetrieve.Retrieve(Int32 ID,
clsZonalA
nalysis& Entity)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(M
ethodBase mb, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInC
ontext, Object[]& outArgs)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMes
sage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
req
Msg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgDa
ta, Int32 type)
at
NZDF.Air.AircraftReview.clsZonalAnalysisRetrieveController.Retrieve(Int32
ID, clsZonalAnalysis& Entity)
at
NZDF.Air.AircraftReview.clsCoveredTasksTester.TestCoveredTaskNTestRefreshW
ithTasks() in
D:\DotNetProjects\ARSSln\ARSNet\testHarness\CoveredTasksTester.vb:
line 264
at ARSNetTester2.Class1.Main() in
D:\DotNetProjects\ARSSln\ARSNetTester2\Clas
s1.vb:line 15
Note that the caught exception is the ApplicationException class that my
exception is inherited from, the message matches the custom exception but the
inner exception object is not present.
(original exception being thrown from class the does NOT inherit from
ServicedComponent) and rethrowing a custom exception
(ARSApplicationException), including the original exception in the custom
exception.
If another application receives the exception from the ServicedComponent,
they get the custom exception message, but do not get the custom
ARSApplicationException and do not get access to the Inner Exception.
Instead they get an ApplicationException - which ARSApplicationException
inherits from
Here is the code (which is executed) from the ServicedComponent class:
Try
....
Catch ex As Exception
Throw New ARSApplicationException("The zonal analysis properties could
not be mapped from the database", ex)
End Try
Here is the ARSApplicationException code:
Imports System.Runtime.Serialization
Imports System.Text
<Serializable()> _
Public Class ARSApplicationException
Inherits ApplicationException
Public Sub New(ByVal Message As String)
MyBase.New(Message)
End Sub
Public Sub New(ByVal Message As String, ByVal InnerException As Exception)
MyBase.New(Message, InnerException)
End Sub
Public Sub New(ByVal Info As SerializationInfo, ByVal Context As
StreamingContext)
MyBase.New(Info, Context)
End Sub
Public Overrides Function ToString() As String
Dim objSB As StringBuilder = New StringBuilder(Me.Message)
If Not Me.InnerException Is Nothing Then
objSB.Append(" - ")
objSB.Append("Inner EXception message: " & Me.InnerException.Message)
End If
objSB.Append(vbCrLf & Me.Source)
objSB.Append(vbCrLf & Me.StackTrace)
Return objSB.ToString()
End Function
End Class
Here is the output after catching the exception in the calling application:
System.ApplicationException: The zonal analysis properties could not be
mapped f
rom the database
Server stack trace:
at NZDF.Air.AircraftReview.IZoneAnalysisRetrieve.Retrieve(Int32 ID,
clsZonalA
nalysis& Entity)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(M
ethodBase mb, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInC
ontext, Object[]& outArgs)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMes
sage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
req
Msg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgDa
ta, Int32 type)
at
NZDF.Air.AircraftReview.clsZonalAnalysisRetrieveController.Retrieve(Int32
ID, clsZonalAnalysis& Entity)
at
NZDF.Air.AircraftReview.clsCoveredTasksTester.TestCoveredTaskNTestRefreshW
ithTasks() in
D:\DotNetProjects\ARSSln\ARSNet\testHarness\CoveredTasksTester.vb:
line 264
at ARSNetTester2.Class1.Main() in
D:\DotNetProjects\ARSSln\ARSNetTester2\Clas
s1.vb:line 15
Note that the caught exception is the ApplicationException class that my
exception is inherited from, the message matches the custom exception but the
inner exception object is not present.