* 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 */
| 44 | * @return Pointer to the exception if the cast is possible, nullptr otherwise |
| 45 | */ |
| 46 | inline 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) */ |