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: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92:
<?php
/**
* This file contains the PHPCapException class.
*/
namespace IU\PHPCap;
/**
* Exception class for PHPCap exceptions. This is the exception that PHPCap will
* throw when it encounters an error.
*
* Example usage:
*
* <code>
* try {
* $projectInfo = $project->exportProjectInfo();
* }
* catch (PhpCapException $exception) {
* print "The following error occurred: {$exception->getMessage()}\n";
* print "Error code: {$exception->getCode()}\n";
* $connectionErrorNumber = $exception->getConnectionErrorNumber();
* if (isset($connectionErrorNumber)) {
* print "A connection error occurred.\n";
* print "Connection error number: {$connectionErrorNumber}\n";
* }
* print "Stack trace:\n{$exception->getTraceAsString()}\n";
* }
* </code>
*
* @see http://php.net/manual/en/class.exception.php
* Information on additional methods provided by parent class Exception.
*/
class PhpCapException extends \Exception
{
/** @var integer|null connection error number */
private $connectionErrorNumber;
/** @var integer|null HTTP status code */
private $httpStatusCode;
/**
* Constructor.
*
* @param string $message the error message.
* @param integer $code the error code.
* @param integer $connectionErrorNumber the connection error number
* (set to null if no connection error occurred).
* @param integer $httpStatusCode the HTTP status code (set to null if no HTTP status code was returned).
* @param \Exception $previous the previous exception.
*/
public function __construct(
$message,
$code,
$connectionErrorNumber = null,
$httpStatusCode = null,
$previous = null
) {
parent::__construct($message, $code, $previous);
$this->connectionErrorNumber = $connectionErrorNumber;
$this->httpStatusCode = $httpStatusCode;
}
/**
* Returns the connection error number, or null if there was no
* connection error. The possible numbers returned will depend
* on the type of connection class being used. For example, if
* cURL is being used, then the cURL error number would be
* returned.
*
* @return integer|null connection error number, or null if there was no connection error.
*/
public function getConnectionErrorNumber()
{
return $this->connectionErrorNumber;
}
/**
* Returns the HTTP status code, or null if this was not set.
*
* @return integer|null HTTP status code, or null if this was not set.
*/
public function getHttpStatusCode()
{
return $this->httpStatusCode;
}
}