Sorry about my English
in WCF, Is there an event or method that catch unhandled exception? or i need to put try/catch in eny mathod
Thanks
Sorry about my English
in WCF, Is there an event or method that catch unhandled exception? or i need to put try/catch in eny mathod
Thanks
You can catch all exceptions with:
try
{
// code
// put your wcf call in here
}
catch (Exception e)
{
// catch stuff in here
}
It's not necessarily a good idea to just catch this though. What I tend to do is let your app crash in testing and then say if "EndPointNotFoundException" is thrown, I just catch this too. For example:
try
{
// wcf stuff
}
catch(EndPointNotFoundException e)
{
// deal with exception
}
catch(ServerTooBusyException e)
{
// deal with exception
}
//etc...
Yes, create a class that implements the IErrorHandler
interface:
Allows an implementer to control the fault message returned to the caller and optionally perform custom error processing such as logging.
You should do Inner and outer TRY/Catch Blocks.
So the first method starts with Try
Then if anything is thrown within another method it defaults to your generic catch in the method that is in the exposed method to return a value to the client.
I always use logging in my catch blocks to tell an admin what went wrong but I aways have the outer catch return a value of something like "Please Except our Appogies the WCF.Blah service has failed. Please review the server logs for complete details"
This way you have error handling, logging and nice messages to your clients..
public class Service1 : IService1
{
public string GetData(int value)
{
try
{
return somemethod(value);
}
catch(Exception ex)
{
LoggingHelper.Log(ex);
return "Please Except our Appogies the WCF.Blah service has failed. Please review the server logs for complete details";
}
}