LoginSignup
1
1

More than 5 years have passed since last update.

エラーコードの値で処理を振り分ける方法

Posted at

準備

あらかじめどこか(APPID_Error.phpあたり)でグローバル定数でエラーコードを定義しておく。

Sample_Error.php
define('E_HOGE_ERROR', 1234);

エラー発生側

   return Ethna::raiseError("ほげほげエラーです。", E_HOGE_ERROR);

エラー受け取り側

Ethna_Error#getCode()でエラーコードを取得できる。

$ret = doSomething();

if (Ethna::isError($ret)) {
    if ($ret->getCode() === E_HOGE_ERROR) {
        // ほげエラーの場合
    } else {
        // それ以外のエラーの場合
    }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1