Javaの独自例外

Javaの独自例外

Javaの独自例外サンプルです。

package jp.co.confrage.infrastructure.exception;

import jp.co.confrage.infrastructure.constant.EmitStatus;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@NoArgsConstructor
@Getter
@Setter
public class HogeException extends Exception {

  /**
   * コンストラクタ.
   *
   * @param status Hogeステータス
   */
  public HogeException(HogeStatus status) {
    this.status = status.getStatus();
    this.emitErrorCode = status.getCode();
  }

  private static final long serialVersionUID = 1L;
  private Integer status;
  private String emitErrorCode;
}
package jp.co.confrage.infrastructure.constant;

/**
* Hoge定義のレスポンスステータス.
*
*/
public enum HogeStatus {

  /** 正常終了. */
  SUCCESS(200, ""),

  /** 正常終了. */
  SUCCESS_ASYNC(202, ""),
  ;
  private Integer status;
  private String code;

  HogeStatus(final Integer status, final String code) {
    this.status = status;
    this.code = code;
  }

  public Integer getStatus() {
    return status;
  }

  public String getCode() {
    return code;
  }
}

 

コメント

タイトルとURLをコピーしました