zoukankan      html  css  js  c++  java
  • struts自定义异常

    步骤1,自定义一个异常类,该类继承RuntimeException,并在该类中放置错误码,该错误码要与在国际化消息文本相同。

    package com.bjsxt.struts;

    public class ErrorCodeException extends RuntimeException {
     
     private String errorCode;
     
     private Object[] args;
     

    //错误码中无占位符的构造方法
     public ErrorCodeException(String errorCode) {
      this(errorCode, null);
     }
     

    //存在占位符的构造方法
     public ErrorCodeException(String errorCode, Object args0) {
      this(errorCode, new Object[]{args0});
     }
     
     public ErrorCodeException(String errorCode, Object[] args) {
      this.errorCode = errorCode;
      this.args = args;
     }
     
     public String getErrorCode() {
      return errorCode;
     }

     public Object[] getArgs() {
      return args;
     }
    }

    步骤2:在需要抛出异常的地方使用该异常

    步骤3:配置异常

  • 相关阅读:
    小程序排错(redis导致)
    linux系统删除-开头文件或目录
    nginx 反向代理
    memcache
    一次故障过程
    json.Decoder vs json.Unmarshal
    ssl中间证书
    作业10:String类
    Angular6如何引入jQuery-knob
    OpenJdk源码下载
  • 原文地址:https://www.cnblogs.com/jinzhengquan/p/1955126.html
Copyright © 2011-2022 走看看