异常类

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. django-内网项目上线测试部署步骤

    1.安装python环境 由于测试环境只有内网,所以在外网同系统上安装python. wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5 ...

  2. Delphi RTTI的应用(一)

    1.获取DbgrdiEH 某一个选项的属性.加载到ComBox procedure TForm1.FormCreate(Sender: TObject); var PropInfo: PPropInf ...

  3. python学习Day1 计算机原理编程思维

    一.学习思想:3W+1H   学什么(what).为什么学(why).用在哪里(where).怎么用(how) 学习编程语言重在代码量.代码量.代码量! 二.计算机五大组成部分,三大核心: 五大组成部 ...

  4. 十九、State 状态模式

    原理: 代码清单: Context public interface Context { void setClock(int hour); void changeState(State state); ...

  5. 迭代器模块 itertools

    无限迭代器 itertools 包自带了三个可以无限迭代的迭代器.这意味着,当你使用他们时,你要知道你需要的到底是最终会停止的迭代器,还是需要无限地迭代下去. 这些无限迭代器在生成数字或者在长度未知的 ...

  6. linux环境启动数据库

    1.查看数据库监听的状态: 监听状态:lsnrctl status  出现如下列截图所示数据,说明切切换账户有问题:切换账户时要家:-:  如 su - oracle 第一步:打开Oracle监听$ ...

  7. 【mac环境】终端配色 & 配置使用ll命令

    1.MAC OS X 命令终端的颜色显示 打开 terminal 会发现 ls 和 grep 后的结果是没有色彩的,这时候可以这么干: 用 vim 打开文件 ~/.bash_profile,然后把下边 ...

  8. 698. Partition to K Equal Sum Subsets 数组分成和相同的k组

    [抄题]: Given an array of integers nums and a positive integer k, find whether it's possible to divide ...

  9. [leetcode]29. Divide Two Integers两整数相除

      Given two integers dividend and divisor, divide two integers without using multiplication, divisio ...

  10. python程序编写简介

    语句和语法 # 注释 \ 转译回车,继续上一行,在一行语句较长的情况下可以使用其来切分成多行,因其可读性差所以不建议使用 : 将两个语句连接到一行,可读性差,不建议使用 : 将代码的头和体分开 语句( ...