MCPcopy Create free account
hub / github.com/Icinga/icinga2 / cast_exception

Function cast_exception

lib/base/exception.cpp:46–71  ·  view source on GitHub ↗

* Attempts to cast an exception to a destination type * * @param obj Exception to be casted * @param src Type information of obj * @param dst Information of which type to cast to * @return Pointer to the exception if the cast is possible, nullptr otherwise */

Source from the content-addressed store, hash-verified

44 * @return Pointer to the exception if the cast is possible, nullptr otherwise
45 */
46inline void *cast_exception(void *obj, const std::type_info *src, const std::type_info *dst)
47{
48#ifdef __GLIBCXX__
49 void *thrown_ptr = obj;
50
51 /* Check if the exception is a pointer type. */
52 if (src->__is_pointer_p())
53 thrown_ptr = *(void **)thrown_ptr;
54
55 if (dst->__do_catch(src, &thrown_ptr, 1))
56 return thrown_ptr;
57 else
58 return nullptr;
59#else /* __GLIBCXX__ */
60 const auto *srcInfo = static_cast<const libcxx_type_info *>(src);
61 const auto *dstInfo = static_cast<const libcxx_type_info *>(dst);
62
63 void *adj = obj;
64
65 if (dstInfo->can_catch(srcInfo, adj))
66 return adj;
67 else
68 return nullptr;
69#endif /* __GLIBCXX__ */
70
71}
72#else /* defined(__GLIBCXX__) || defined(_LIBCPPABI_VERSION) */
73#define NO_CAST_EXCEPTION
74#endif /* defined(__GLIBCXX__) || defined(_LIBCPPABI_VERSION) */

Callers 1

exception.cppFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected