Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Custom Exceptions

Reply
Thread Tools

Custom Exceptions

 
 
Chris Dunaway
Guest
Posts: n/a
 
      01-13-2004
I'm creating a Web service and a Windows Forms application to consume it.
My question is about throwing a custom exception inside the WebService.
Can that be done, and can the custom web service be handled in the Windows
Forms app?

For example, suppose in my WebService, I have the following exception
class:

'\\\\\
<Serializable()> _
Public Class WebServiceException
Inherits ApplicationException <<<<<<< Is this correct?

'Code for exception class here

End Class
../////

And then within my web method:

'\\\\\
<WebMethod()> _
Public Sub SomeWebMethod()

If SomeCondition Then
Throw New WebServiceException
End If
End Sub
'/////


On the Windows Forms client, I can only trap for generic exceptions not my
custom exception type:

Try
WebService.SomeWebMethod
Catch ex As WebServiceException <<<<<<<<< This doesn't work
'Handle it
End Try


Anyone know of a way to achieve this?

Thanks for any pointers

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
 
Reply With Quote
 
 
 
 
Jan Tielens
Guest
Posts: n/a
 
      01-14-2004
Check out following article that covers this topic:
http://www.microsoft.com/belux/nl/ms...ens/soapexcept
ions.mspx

Throwing SoapExceptions

Summary:

Sometimes things can go wrong when code is executed, so Exceptions are
thrown. When your application exposes services through a webservice layer,
SoapExceptions are thrown from the server to the client. By default normal
Exceptions are converted to a SoapException, resulting in a rather ugly
Exception containing all information concatenated in a long String. But
luckily the SOAP protocol allows any XML document to be included in SOAP
error messages. This article shows how to build some helper classes to
easily pass error information from the server to the client through a
webservice layer.

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan


"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
newsjwg5qhhnul.1w1a09j3evsz7$....
> I'm creating a Web service and a Windows Forms application to consume it.
> My question is about throwing a custom exception inside the WebService.
> Can that be done, and can the custom web service be handled in the Windows
> Forms app?
>
> For example, suppose in my WebService, I have the following exception
> class:
>
> '\\\\\
> <Serializable()> _
> Public Class WebServiceException
> Inherits ApplicationException <<<<<<< Is this correct?
>
> 'Code for exception class here
>
> End Class
> ./////
>
> And then within my web method:
>
> '\\\\\
> <WebMethod()> _
> Public Sub SomeWebMethod()
>
> If SomeCondition Then
> Throw New WebServiceException
> End If
> End Sub
> '/////
>
>
> On the Windows Forms client, I can only trap for generic exceptions not my
> custom exception type:
>
> Try
> WebService.SomeWebMethod
> Catch ex As WebServiceException <<<<<<<<< This doesn't work
> 'Handle it
> End Try
>
>
> Anyone know of a way to achieve this?
>
> Thanks for any pointers
>
> --
> Chris
>
> To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
> address.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exceptions - How do you make it work like built-in exceptions? Lie Python 3 01-14-2008 06:45 PM
Exceptions + Performance on path without exceptions gratch06@gmail.com C++ 3 04-16-2007 08:52 PM
Checked exceptions vs unchecked exceptions Ahmed Moustafa Java 5 07-14-2004 01:46 PM
Custom Exceptions with Web Services Chris Dunaway ASP .Net 1 01-13-2004 10:35 PM
Custom exceptions -- inherit from exceptions.Exception? Paul Miller Python 3 11-12-2003 09:24 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57