<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">[ removing cfe-dev]</div><div class=""><br class=""></div>On Jan 26, 2021, at 7:25 AM, Ilia K via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:<br class=""><div><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi!<br class=""><br class="">It turned out that I cannot catch `std::bad_alloc&` thrown by the `operator new` when compiling 1.cpp with -fno-rtti and linking against system's libc++.1.dylib/libc++abi.dylib on macOS. This scenario works on Linux, and according to the official libc++ page it is supported ("However linking against it with -fno-rtti is supported", <a href="https://libcxx.llvm.org/" class="">https://libcxx.llvm.org/</a>), however the following code is aborted due to an unhandled exception:<br class=""><br class="">```1.cpp<br class="">#include <cstdio><br class="">#include <new><br class=""><br class="">int main() {<br class="">    try {<br class="">        ::operator new(-1);<br class="">    } catch (std::bad_alloc& e) {<br class="">        printf("caught %s\n", e.what());<br class="">    }<br class="">    return 0;<br class="">}<br class="">```<br class=""><br class="">Compile & run:<br class="">```<br class="">$ clang++ -fno-rtti 1.cpp -o 1_no_rtti<br class="">$ ./1_no_rtti<br class="">libc++abi.dylib: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc<br class="">Abort trap: 6<br class="">```<br class=""></div></div></blockquote><div><br class=""></div><div><br class=""></div>That sounds right to me.</div><div>If you don’t have RTTI, then the catch mechanism cannot match up the type of the exception and the type that you’re looking to catch.</div><div>You should be able to catch (…), though.</div><div><br class=""></div><div>— Marshall</div></body></html>