Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB7
Expertise: Intermediate
Mar 24, 2003

GetWSException - Extracting the name of the SoapException's inner exception

' Extract the name of the SoapException's (the type of exception thrown by a 
' web service) "inner" exception.
'
' Example:
'   Try
'       ' this call throws an exception
'       Dim service As New localhost.SampleService()
'       service.ThrowAnException()
'   Catch ex As SoapException When ex.Code.Equals
' (SoapException.VersionMismatchFaultCode)
'   
'   Catch ex As SoapException When ex.Code.Equals(SoapException.ServerFaultCode)
'       lblMessage.Text = "SOAP Exception: " & ex.Message
'   Catch ex As SoapException When GetWSException(ex) = 
' "System.NullReferenceException"
'       ' get details from the OuterXml property
'       lblMessage.Text = ex.Detail.OuterXml
'   End Try

Function GetWSException(ByVal ex As System.Web.Services.Protocols.SoapException) _
    As String
    ' parse the exception's Message property.
    Dim mc As System.Text.RegularExpressions.MatchCollection = _
        System.Text.RegularExpressions.Regex.Matches(ex.Message, _
        "---> ([^:]+):")
    If mc.Count >= 1 Then
        ' we've found a match - the first ground contains the value.
        Return mc.Item(0).Groups(1).Value
    End If
End Function
Marco Bellinaso
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date