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

---

# Exception::__construct( string $message, string $type, mixed $data = null, integer $code )

## In this article

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

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

Create a new exception

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

 `$message`stringrequired

Exception message

`$type`stringrequired

Exception type

`$data`mixedoptional

Associated data

Default:`null`

`$code`integerrequired

Exception numerical code, if applicable

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

    ```php
    public function __construct($message, $type, $data = null, $code = 0) {
    	parent::__construct($message, $code);

    	$this->type = $type;
    	$this->data = $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/7.0/src/wp-includes/Requests/src/Exception.php#L40)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/Requests/src/Exception.php#L40-L45)

## 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__construct%2F)
before being able to contribute a note or feedback.