Title: Exception
Published: March 29, 2023
Last modified: November 8, 2023

---

# class Exception {}

## In this article

 * [Methods](https://developer.wordpress.org/reference/classes/wporg-requests-exception/?output_format=md#methods)
 * [Source](https://developer.wordpress.org/reference/classes/wporg-requests-exception/?output_format=md#source)

[ Back to top](https://developer.wordpress.org/reference/classes/wporg-requests-exception/?output_format=md#wp--skip-link--target)

Exception for HTTP requests

## 󠀁[Methods](https://developer.wordpress.org/reference/classes/wporg-requests-exception/?output_format=md#methods)󠁿

| Name | Description | 
| [Exception::__construct](https://developer.wordpress.org/reference/classes/wporg-requests-exception/__construct/) | Create a new exception | 
| [Exception::getData](https://developer.wordpress.org/reference/classes/wporg-requests-exception/getdata/) | Gives any relevant data | 
| [Exception::getType](https://developer.wordpress.org/reference/classes/wporg-requests-exception/gettype/) | Like [\Exception::getCode()](https://developer.wordpress.org/reference/classes/Exception/getCode/), but a string code. |

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wporg-requests-exception/?output_format=md#source)󠁿

    ```php
    class Exception extends PHPException {
    	/**
    	 * Type of exception
    	 *
    	 * @var string
    	 */
    	protected $type;

    	/**
    	 * Data associated with the exception
    	 *
    	 * @var mixed
    	 */
    	protected $data;

    	/**
    	 * Create a new exception
    	 *
    	 * @param string $message Exception message
    	 * @param string $type Exception type
    	 * @param mixed $data Associated data
    	 * @param integer $code Exception numerical code, if applicable
    	 */
    	public function __construct($message, $type, $data = null, $code = 0) {
    		parent::__construct($message, $code);

    		$this->type = $type;
    		$this->data = $data;
    	}

    	/**
    	 * Like \Exception::getCode(), but a string code.
    	 *
    	 * @codeCoverageIgnore
    	 * @return string
    	 */
    	public function getType() {
    		return $this->type;
    	}

    	/**
    	 * Gives any relevant data
    	 *
    	 * @codeCoverageIgnore
    	 * @return mixed
    	 */
    	public function getData() {
    		return $this->data;
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/src/exception.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/Requests/src/Exception.php#L17)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/Requests/src/Exception.php#L17-L66)

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwporg-requests-exception%2F)
before being able to contribute a note or feedback.