0

我正在使用带有自定义异常的Agatha框架。我有一个例外,我在配置我的请求MyException时将其指定为:BusinessExceptionType

new ServiceLayerConfiguration(Assembly.GetExecutingAssembly(), typeof(SomeRequestResponse.MakeARequest).Assembly, typeof(Container)) { BusinessExceptionType = typeof(MyException) }.Initialize();

这就是我抛出异常的方式:

throw new MyException(message);

但是,当引发异常时,MyException不会将其识别为BusinessExceptionType. 我如何让它被识别为一个BusinessExceptionType?以下条件不成立。

if (response.ExceptionType == ExceptionType.Business)

这是异常类:

public class MyException : Exception
{
    public MyException()
    {

    }

    public MyException(string message) : base(message)
    {

    }

    public MyException(string message, Exception inner) : base(message, inner)
    {

    }

    protected MyException(SerializationInfo info, StreamingContext context) : base(info, context)
    {

    }
}

更新: 似乎BusinessExceptionType设置serviceLayerConfiguration正确,直到我在BusinessExceptionType成为null. 在配置请求和发出我的第一个请求之间的某个地方,它变成了null. 要么,要么它serviceLayerConfigurationRequestProcessor.cs. 对此的任何帮助表示赞赏。

4

1 回答 1

0

我发现你必须在抛出它之前在响应中设置异常类型。

return new SomeRequestResponse.MakeAResponse() { Exception = new Exception(ex), ExceptionType = ExceptionType.Business };

那么在你的消费者中,这个陈述将是真实的:

if (response.ExceptionType == ExceptionType.Business)

如果您想创建自己的例外,也可以这样做:

return new MakeARequestResponse.MakeAResponse()
{
    Exception = new ExceptionInfo(new Exception("Whatever you want to say.")),
    ExceptionType = ExceptionType.Business
};
于 2015-07-21T14:19:35.897 回答