The ExceptionHandler(set inside the overridden Configure method of AppHostBase) of servicestack has the 'exception' parameter of generic Exception type in the lambda.
this.ExceptionHandler = (httpReq, httpResp, operationName, exception) =>
{
if(exception is ArgumentException)
{
// some code
}
}
Inside the lambda, I wish to add a specific condition if the exception is of ArgumentException type.
Is there any way to identify which specific type of exception was thrown?
Checking the type with 'is' keyword is not working as given by this link
FYI, a custom ServiceRunner is implemented for the servicestack instance that we use.
The piece of code that caused the
ArgumentExceptionwasFor some reason, the exception object cannot be recognised as an
ArgumentExceptioninside theExceptionHandlerAlthough, as mentioned in the link(pls refer question) the InnerException can be identified using
iskeyword.Hence the solution applied was to throw the
ArgumentExceptionas an inner exception as follows:Hence, now the
ExceptionHandlercode is: