开发者

Handle exceptions from WS

开发者 https://www.devze.com 2022-12-09 09:42 出处:网络
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开发者_StackOverflow have to write many try...catch to handle t

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开发者_StackOverflow have to write many try...catch to handle them all.

Thanks


use

  AppDomain.CurrentDomain.UnhandledException

before creating winform, you need to add this line

 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号