Hi, I have a Web Reference to a remote Web Service, which is called in several different classes. I'd like to catch all exceptions coming from this Web Service only. How can I do that (for example extending it's base, auto generated class) without interfering and modifying all upper level code?
A:
You can't, and why do you want to? It's almost always a mistake to "catch all exceptions" or "handle all exceptions". What are you trying to accomplish?
- I'd suggest you log it on the server, not the client.
- What will you be doing when you hide the exception from the upper layers? Pretending it didn't happen?
It might make sense to wrap the SoapException in one of your own. Maybe. That's only because SoapException is so specific to web services. In this case, yes, you need to wrap every call in a try/catch. The best way to do this would be in a facade class, which could also have the common code for wrapping the SoapException or translating it into one of your own.
Still, unless you're ready to take control of the code generation, you'll wind up doing this by hand.
John Saunders
2009-05-12 21:20:17
John, I've basically made a ws proxy between the database and the application. I've created a custom soapexception class, for encapsulating all exceptions in the webservice. I want to log it, and want to hide it from the upper level business logic.
balint
2009-05-12 21:34:24
1) I need to log on the clients too.2) I would like to "unpack" and deliver only the core-exception, not the encapsulated one.
balint
2009-05-12 23:27:49
+1
A:
See this other question:
Capture all unhandled exceptions automatically with WebService
codeulike
2009-05-12 21:23:47