Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Exception handling 使用ServiceStack未处理的异常行为_Exception Handling_<img Src="//i.stack.imgur.com/WM7S8.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">servicestack - Fatal编程技术网 servicestack,Exception Handling,servicestack" /> servicestack,Exception Handling,servicestack" />

Exception handling 使用ServiceStack未处理的异常行为

Exception handling 使用ServiceStack未处理的异常行为,exception-handling,servicestack,Exception Handling,servicestack,我希望在不向响应DTO手动添加ResponseStatus的情况下获得自动异常序列化 基于未处理异常行为的信息,我编写了以下代码 public class ContactService : RestServiceBase<Contact> { public override object OnGet(Contact request) { return ContactApi.GetContactInfo(request); } //To

我希望在不向响应DTO手动添加ResponseStatus的情况下获得自动异常序列化

基于未处理异常行为的信息,我编写了以下代码

public class ContactService : RestServiceBase<Contact>
{
    public override object OnGet(Contact request)
    {
        return ContactApi.GetContactInfo(request);
    }

    //To trigger the serialization of the Exception to ResponseStatus
    protected override object HandleException(Contact request, Exception ex)
    {
        throw ex;
    }

<snip />
}

不完全清楚你到底想要什么。当出现错误时,您希望消费者最终看到什么?你能给我们展示一个你想要实现的输出的例子吗?更新了问题,包括我想要实现的输出。
{
  "ResponseStatus":{
  "ErrorCode":"ApplicationException",
  "Message":"CRASH",
  }
}