异常类

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. python至winreg模块

    _winreg模块在python3中已经改名了 https://blog.csdn.net/zhangxiaoyang0/article/details/72236305?fps=1&loca ...

  2. session and cookie简析

    无状态应用程序(cookies.session等机制出现的背景) Web应用程序服务器通常是“无状态的”: 每个HTTP请求都是独立的; 服务器无法判断2个请求是来自同一个浏览器还是用户. Web服务 ...

  3. C# 调用程序集方法

    加载程序集 (Assembly类) 使用 Assembly 类可以加载程序集.浏览程序集的元数据和构成部分.发现程序集中包含的类型以及创建这些类型的实例 // 加载该路径的程序集 Assembly a ...

  4. <记录> PHP监控进程状态,完成掉线自动重启

    1. 利用Shell脚本实现 #!/bin/bash PORT= while [ true ];do read -p "please enter the port that you want ...

  5. c#读取文本并生成txt

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. redis安装--单机

    本例基于CentOS7.2系统安装 环境需求: 关闭防护墙,selinux 安装好gcc等编译需要的组件 yum -y install gcc c++ 到redis官网下载合适版本的redis安装包, ...

  7. 【原】The Linux Command Line - Workiing with commands

    ● type – Indicate how a command name is interpreted● which – Display which executable program will b ...

  8. java学习笔记(十):scanner输入

    可以通过 Scanner 类来获取用户的输入. 通过next()类和nextLine()类来获取字符串. 通过 Scanner 类的 next() 类来获取输入的字符串. import java.ut ...

  9. NSLog无法使用

    iOS/macos 中 #import<foundation/foundation.h> nslog不能用 如果项目中包含c/c++程序代码 将其后缀修改成.m .mm 将项目的build ...

  10. FortiGate外网IPSec链路及运维专线链路到个别网段不通

    1.现状: 如图,用户网段有192.168.50.0/24.192.168.51.0/24和192.168.52.0/24.192.168.53.0/24.在防火墙上有静态路由到运维专线的10.160 ...