Consider this code:
[GlobalErrorBehaviorAttribute(typeof(GlobalErrorHandler))]
public class Service1 : IService1
{
public string Recursive(int value)
{
Recursive(value);
return string.Format("You entered: {0}", value);
}
and this is my GlobalErrorHandler
:
public class GlobalErrorHandler : IErrorHandler
{
public bool HandleError(Exception error)
{
string path = HostingEnvironment.ApplicationPhysicalPath;
using (TextWriter tw = File.AppendText(Path.Combine(path, @"d:\\IIS.Log")))
{
if (error != null)
{
tw.WriteLine("Exception:{0}{1}Method: {2}{3}Message:{4}",
error.GetType().Name, Environment.NewLine, error.TargetSite.Name,
Environment.NewLine, error.Message + Environment.NewLine);
}
tw.Close();
}
return true;
}
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
var newEx = new FaultException(
string.Format("Exception caught at GlobalErrorHandler{0}Method: {1}{2}Message:{3}",
Environment.NewLine, error.TargetSite.Name, Environment.NewLine, error.Message));
MessageFault msgFault = newEx.CreateMessageFault();
fault = Message.CreateMessage(version, msgFault, newEx.Action);
}
}
When I call Recursive
in the WCF Test Client I get this error. Why can't I handle a StackOverflowException
?
Is there any way for handle such this error?