# std::set_unexpected

> C++ Atlas: `cppatlas.com/w/cpp/error/set_unexpected` | Source: https://en.cppreference.com/w/cpp/error/set_unexpected | Domain: Diagnostics | Standards: C++11, C++17

Makes f the new global std::unexpected_handler and returns the previously installed std::unexpected_handler.

## Official Specification Summary (cppreference)

```cpp
// Defined in header <exception>
std::unexpected_handler set_unexpected( std::unexpected_handler f ) throw(); // (until C++11)
std::unexpected_handler set_unexpected( std::unexpected_handler f ) noexcept; // (deprecated in C++11) (removed in C++17)
```

Makes `f` the new global `std::unexpected_handler` and returns the previously installed `std::unexpected_handler`.

This function is thread-safe. Every call to `std::set_unexpected` *synchronizes-with* (see `std::memory_order`) the subsequent calls to `std::set_unexpected` and `std::get_unexpected` (since C++11)

### Parameters

- `f` - pointer to function of type `std::unexpected_handler`, or null pointer

### Return value

The previously-installed unexpected handler, or a null pointer value if none was installed.

### See also

- [`unexpected`](https://en.cppreference.com/w/cpp/error/unexpected) (deprecated in C++11): function called when dynamic exception specification is violated (function)
- [`get_unexpected`](https://en.cppreference.com/w/cpp/error/get_unexpected) (deprecated in C++11): obtains the current `unexpected_handler` (function)
- [`unexpected_handler`](https://en.cppreference.com/w/cpp/error/unexpected_handler) (deprecated in C++11): the type of the function called by `std::unexpected` (typedef)

---
Attribution: content from https://en.cppreference.com/w/cpp/error/set_unexpected (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.