class-base-exception.php
1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* Class Base_Exception
*
* @package WooCommerce\Payments
*/
namespace WCPay\Exceptions;
use Exception;
defined( 'ABSPATH' ) || exit;
/**
* Abstract class for payments extension exceptions, where we allow to inject
* human-friendly error codes, e.g. 'order_not_found'.
*/
abstract class Base_Exception extends Exception {
/**
* String error code, for example 'order_not_found'.
*
* @var string
*/
private $error_code;
/**
* Constructor, including the usual $message, $code, and $previous,
* and a new parameter $error_code.
*
* @param string $message The Exception message to throw.
* @param string $error_code String error code.
* @param int $code The Exception code.
* @param \Throwable $previous The previous exception used for the exception chaining.
*/
public function __construct( $message, $error_code, $code = 0, $previous = null ) {
$this->error_code = $error_code;
parent::__construct( $message, $code, $previous );
}
/**
* Returns the error code.
*
* @return string Error code, for example 'order_not_found'.
*/
public function get_error_code() {
return $this->error_code;
}
}