异常类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace EasErpQuerySys.EasApplication
{
[Serializable]
public class EasWebServiceException : ApplicationException
{
private readonly ExceptionResult _exceptionResult;
public EasWebServiceException() { }
public EasWebServiceException(string resultStatus, string resultMsg) : base(resultStatus)
{
_exceptionResult = new ExceptionResult { resultMsg = resultMsg, resultStatus = resultStatus };
}
public ExceptionResult GetExceptionResult()
{
return _exceptionResult;
}
}
public class ExceptionResult
{
public string resultStatus { get; set; }
public string resultMsg { get; set; }
}
}

触发类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace EasErpQuerySys.EasApplication
{
public class EasAppService : IEasAppService
{
public string Test()
{ throw new EasWebServiceException("失败", "失败了滚蛋"); }
}
}

捕获类

using EasErpQuerySys.EasApplication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace test
{
class Program
{
static void Main(string[] args)
{
IEasAppService easAppService = new EasAppService(); try
{
easAppService.Test();
}
catch (EasWebServiceException e)
{
var tt = e.GetExceptionResult();
Console.WriteLine(tt.resultMsg);
Console.WriteLine(tt.resultStatus);
Console.ReadLine();
}
}
}
}

输出结果:

C#自定义异常 统一异常处理的更多相关文章

  1. js构建ui的统一异常处理方案(四)

    上一篇我们介绍了统一异常处理方案的设计方案,这一篇我们将直接做一个小例子,验证我们的设计方案. 例子是一个todo的列表界面(页面代码参考于https://github.com/zongxiao/Dj ...

  2. 使用Spring MVC统一异常处理实战

    1 描述 在J2EE项目的开发中,不管是对底层的数据库操作过程,还是业务层的处理过程,还是控制层的处理过程,都不可避免会遇到各种可预知的.不可预知的异常需要处理.每个过程都单独处理异常,系统的代码耦合 ...

  3. spring boot / cloud (二) 规范响应格式以及统一异常处理

    spring boot / cloud (二) 规范响应格式以及统一异常处理 前言 为什么规范响应格式? 我认为,采用预先约定好的数据格式,将返回数据(无论是正常的还是异常的)规范起来,有助于提高团队 ...

  4. Spring Boot中Web应用的统一异常处理

    我们在做Web应用的时候,请求处理过程中发生错误是非常常见的情况.Spring Boot提供了一个默认的映射:/error,当处理中抛出异常之后,会转到该请求中处理,并且该请求有一个全局的错误页面用来 ...

  5. spring boot配置统一异常处理

    基于@ControllerAdvice的统一异常处理 >.这里ServerException是我自定义的异常,和普通Exception分开处理 >.这里的RequestResult是我自定 ...

  6. 【SpringMVC学习07】SpringMVC中的统一异常处理

    我们知道,系统中异常包括:编译时异常和运行时异常RuntimeException,前者通过捕获异常从而获取异常信息,后者主要通过规范代码开发.测试通过手段减少运行时异常的发生.在开发中,不管是dao层 ...

  7. SpringBoot 统一异常处理

    统一异常处理: @ControllerAdvice public class GlobalExceptionHandler { private Logger logger = LoggerFactor ...

  8. 基于spring boot的统一异常处理

    一.springboot的默认异常处理 Spring Boot提供了一个默认的映射:/error,当处理中抛出异常之后,会转到该请求中处理,并且该请求有一个全局的错误页面用来展示异常内容. 例如这里我 ...

  9. 【统一异常处理】@ControllerAdvice + @ExceptionHandler 全局处理 Controller 层异常

    1.利用springmvc注解对Controller层异常全局处理 对于与数据库相关的 Spring MVC 项目,我们通常会把 事务 配置在 Service层,当数据库操作失败时让 Service ...

随机推荐

  1. Innodb锁相关总结

    一.InnoDB共有七种类型的锁: (1)共享/排它锁(Shared and Exclusive Locks) (2)意向锁(Intention Locks) (3)插入意向锁(Insert Inte ...

  2. ---command line edit and histroy of perl cpan shell

    https://www.redhat.com/archives/psyche-list/2003-February/msg00494.html perl -MCPAN -e shell > in ...

  3. Spring中注入对象为NULL

    Java工程报错, java.lang.reflect.InvocationTargetException,网上搜索过后,发现是注入错误,通过调试发现,具体报错位置是某个dao层对象为null,进而引 ...

  4. Linux命令:logout

    logout [n] 退出当前shell,给父shell返回状态码n. 参考return.

  5. 原生js实现Base64编码解码

    注:ie10+ var str = window.btoa("liusong"); console.log(str); var s = window.atob("bGl1 ...

  6. hive的常用操作

    1.hive的数据类型 tinyint/smallint/int/bigint tinyint:从 0 到 255 的整型数据 smallint:从 0 到 65535 的整型数据 int:从 0 到 ...

  7. python--第十天总结(Select/Poll/Epoll使用 )

    首先列一下,sellect.poll.epoll三者的区别 select select最早于1983年出现在4.2BSD中,它通过一个select()系统调用来监视多个文件描述符的数组,当select ...

  8. 10.13 新版本go on~

    上午1.5 终审 and 排期 合同管理那边又是切换选项时各种联动,我第一想法是 好麻烦,不想做这个...第二想法才是给我做吧 锻炼锻炼我 然后 分任务的时候 分给我了,,哈哈 开心 虽然我没想躲 但 ...

  9. python的基本用法(四)文件操作使用

    #读文件,文件必须存在才能读f=open('操作文件',encoding='utf-8')res =f.read()print(res)f.close()#写文件fw=open('操作文件',mode ...

  10. js函数内未声明变量

    <script> function test(){ testd = "Hello"; } test(); alert(testd); </script> 当 ...