导致的那段代码ArgumentException
是
return serializer.Deserialize(querystring, TEMP);
由于某种原因,无法将异常对象识别为ArgumentException
内部ExceptionHandler
this.ExceptionHandler = (httpReq, httpResp, operationName, exception) =>
{
httpResp.StatusCode = 500;
bool isArgEx = exception is ArgumentException; // returns false
if(isArgEx)
{
//do something
}
}
虽然,如链接中所述(请参阅问题),可以使用关键字识别InnerException 。is
因此,应用的解决方案是将 抛出ArgumentException
为内部异常,如下所示:
public const string ARG_EX_MSG = "Deserialize|ArgumentException";
try
{
return serializer.Deserialize(querystring, TEMP);
}
catch(ArgumentException argEx)
{
throw new Exception(ARG_EX_MSG, argEx);
}
因此,现在的ExceptionHandler
代码是:
this.ExceptionHandler = (httpReq, httpResp, operationName, exception) =>
{
httpResp.StatusCode = 500;
bool isArgEx = exception.InnerException is ArgumentException; // returns true
if(isArgEx)
{
//do something
}
}