views:

55

answers:

2

Hi, I've WS client written in C#. Is there any way I can handle all exceptions in one place? Now WS methods are executed in many places so I have to write many try...catch to handle them all.

Thanks

A: 

Use svcutil.exe (In Visual Studio: "Add Service Reference") to generate a WCF client, even if it is just a plain old (asmx) web service. Then you can inject your own implementation of the IErrorHandler interface. In this case you just need to provide an implementation of IErrorHandler.HandleError since the ProvideFault method would only be used on the service side.

Marc Wittke
+1  A: 

use

  AppDomain.CurrentDomain.UnhandledException

before creating winform, you need to add this line

 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Avram
It works fine :) Thanks :)
arek