异常类

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. android toolbar使用记录

    1.打开Project structure,选择app modules,切换到Dependencies添加com.android.support.design.26.0.0.alpha1 2.在lay ...

  2. 活用RPM获取包的信息

    rpm -q 功效大 如果你想要在系统上安装.卸载或是升级软件,需要对系统软件进行查询:或是有如下的场景: 安装了一个软件,需要知道这个软件的版本. 遇到一个文件,不认识它,需要知道它是什么软件,有什 ...

  3. byobu 禁止窗口名称随目录变化

    It looks like the config set-window-option -g automatic-rename off doesn't work. When I added the fo ...

  4. 远程桌面 把explorer关掉了

    用Ctrl+Alt+End调出远程桌面的任务管理器.然后,运行explorer.exe即可重启该服务.

  5. Redux使用教程

    在开始之前,需要安装环境,node.js可以使用npm管理包,开发的工具webstorm可以创建相应的项目. 项目中redux是管理全局的同一个store,React-router是管理路由的,这里只 ...

  6. @RestController 与 @Controller @RequestMapping("/") 区别很大

    后者可以通过返回字符串,返回到指定路径的html http://localhost:8080/  这样显示 ,但是仍以get方式请求的. https://www.cnblogs.com/zgqys19 ...

  7. 为docker私有registry配置nginx反向代理

    公司的Docker私有registry已经搭建好了,用官方的registry image很容易就搭建好了.现在就是要用nginx的反向代理把它放出来,以便在外网可以访问. 我的上一篇blog 讲了如何 ...

  8. openvpn显示连接成功但是无法进行git操作

    使用openvpn连接公司内网以进行git操作.以管理员身份运行openvpn gui,一段时间后提示连接成功,右下角图标变成绿色,但是进行git操作,每次都发生失败,提示连接不上.右键点击openv ...

  9. Java的三种代理模式(Spring动态代理对象)

    Java的三种代理模式 1.代理模式 代理(Proxy)是一种设计模式,提供了对目标对象另外的访问方式;即通过代理对象访问目标对象.这样做的好处是:可以在目标对象实现的基础上,增强额外的功能操作,即扩 ...

  10. Add custom field in Material Master

    1.Add fields in the Append Structure of table MARA. 2.Configure SPRO IMG -> Logistics General -&g ...