1*ab8e5256SAndreas Gohr<?php 2*ab8e5256SAndreas Gohr 3*ab8e5256SAndreas Gohrnamespace splitbrain\phpcli; 4*ab8e5256SAndreas Gohr 5*ab8e5256SAndreas Gohr/** 6*ab8e5256SAndreas Gohr * Class Exception 7*ab8e5256SAndreas Gohr * 8*ab8e5256SAndreas Gohr * The code is used as exit code for the CLI tool. This should probably be extended. Many cases just fall back to the 9*ab8e5256SAndreas Gohr * E_ANY code. 10*ab8e5256SAndreas Gohr * 11*ab8e5256SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 12*ab8e5256SAndreas Gohr * @license MIT 13*ab8e5256SAndreas Gohr */ 14*ab8e5256SAndreas Gohrclass Exception extends \RuntimeException 15*ab8e5256SAndreas Gohr{ 16*ab8e5256SAndreas Gohr const E_ANY = -1; // no error code specified 17*ab8e5256SAndreas Gohr const E_UNKNOWN_OPT = 1; //Unrecognized option 18*ab8e5256SAndreas Gohr const E_OPT_ARG_REQUIRED = 2; //Option requires argument 19*ab8e5256SAndreas Gohr const E_OPT_ARG_DENIED = 3; //Option not allowed argument 20*ab8e5256SAndreas Gohr const E_OPT_ABIGUOUS = 4; //Option abiguous 21*ab8e5256SAndreas Gohr const E_ARG_READ = 5; //Could not read argv 22*ab8e5256SAndreas Gohr 23*ab8e5256SAndreas Gohr /** 24*ab8e5256SAndreas Gohr * @param string $message The Exception message to throw. 25*ab8e5256SAndreas Gohr * @param int $code The Exception code 26*ab8e5256SAndreas Gohr * @param \Exception $previous The previous exception used for the exception chaining. 27*ab8e5256SAndreas Gohr */ 28*ab8e5256SAndreas Gohr public function __construct($message = "", $code = 0, \Exception $previous = null) 29*ab8e5256SAndreas Gohr { 30*ab8e5256SAndreas Gohr if (!$code) { 31*ab8e5256SAndreas Gohr $code = self::E_ANY; 32*ab8e5256SAndreas Gohr } 33*ab8e5256SAndreas Gohr parent::__construct($message, $code, $previous); 34*ab8e5256SAndreas Gohr } 35*ab8e5256SAndreas Gohr} 36