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

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

try_ catch_ Statement

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

The syntax is:

try_
[
    sequenced_statements
]
.catch_<exception_type>()
[
    sequenced_statements
]
.catch_<another_exception_type>(local-id)
[
    sequenced_statements
]
...
.catch_all
[
    sequenced_statement
]

Note the usual underscore after try and catch, and the extra parentheses required after the catch.

The second form of catch statement can refer thrown exception using specified local-id, which is Local Variables, in sequenced_statements.

Example: The following code calls the (lazy) function f for each element, and prints messages about different exception types it catches.

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

PrevUpHomeNext