CARLA
Loading...
Searching...
No Matches
Exception.h
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8#include <exception>
9
10
11
12// =============================================================================
13// -- Define carla::throw_exception --------------------------------------------
14// =============================================================================
15
16#ifdef LIBCARLA_NO_EXCEPTIONS
17
18namespace carla
19{
20 /// User defined function, similar to Boost throw_exception.
21 ///
22 /// @important Boost exceptions are also routed to this function.
23 ///
24 /// When compiled with LIBCARLA_NO_EXCEPTIONS, this function is left undefined
25 /// in LibCarla, and the modules using LibCarla are expected to supply an
26 /// appropriate definition. Callers of throw_exception are allowed to assume
27 /// that the function never returns; therefore, if the user-defined
28 /// throw_exception returns, the behavior is undefined.
29 [[noreturn]]
30 void throw_exception(const std::exception &e);
31
32} // namespace carla
33
34#else
35
36namespace carla
37{
38 /// Templated on the static type so the thrown object keeps its dynamic
39 /// type: taking a `const std::exception &` and `throw e;` would slice
40 /// every carla::client error down to a bare std::exception (what() ==
41 /// "std::exception"), losing the server's message.
42 template <typename ExceptionT>
43 [[noreturn]]
44 inline void throw_exception(const ExceptionT &e)
45 {
46 throw e;
47 }
48} // namespace carla
49
50#endif // LIBCARLA_NO_EXCEPTIONS
51
52
53
54// =============================================================================
55// -- Define boost::throw_exception --------------------------------------------
56// =============================================================================
57
58#ifdef BOOST_NO_EXCEPTIONS
59#include <boost/assert/source_location.hpp>
60
61namespace boost
62{
63 BOOST_NORETURN
64 inline void throw_exception(const std::exception &e)
65 {
67 }
68
69 BOOST_NORETURN
70 inline void throw_exception(const std::exception &e, boost::source_location const& /*loc*/)
71 {
73 }
74} // namespace boost
75#endif // BOOST_NO_EXCEPTIONS
76
77
78
79// =============================================================================
80// -- Workaround for Boost.Asio bundled with rpclib ----------------------------
81// =============================================================================
82
83#ifdef ASIO_NO_EXCEPTIONS
84namespace clmdep_asio
85{
86 namespace detail
87 {
88 [[noreturn]]
89 inline void throw_exception(const std::exception& e)
90 {
92 }
93 } // namespace detail
94} // namespace clmdep_asio
95#endif // ASIO_NO_EXCEPTIONS
This file contains definitions of common data structures used in traffic manager.
void throw_exception(const ExceptionT &e)
Templated on the static type so the thrown object keeps its dynamic type: taking a const std::excepti...
Definition Exception.h:44