Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Click here to view the latest version of this page.
PrevUpHomeNext

throw_

#include <boost/phoenix/statement/throw.hpp>

As a natural companion to the try/catch support, the statement module provides lazy throwing and re-throwing of exceptions.

The syntax to throw an exception is:

throw_(exception_expression)

The syntax to re-throw an exception is:

throw_()

Example: This code extends the try/catch example, re-throwing exceptions derived from runtime_error or exception, and translating other exception types to runtime_errors.

try_
[
    f(arg1)
]
.catch_<runtime_error>()
[
    cout << val("caught runtime error or derived\n"),
    throw_()
]
.catch_<exception>()
[
    cout << val("caught exception or derived\n"),
    throw_()
]
.catch_all
[
    cout << val("caught some other type of exception\n"),
    throw_(runtime_error("translated exception"))
]

PrevUpHomeNext