You are misunderstanding. Two-phase-unwinding first searches the stack for a matching catch-block; and then in the second phase unwinds the stack (calling destructors). By capturing the stack trace within the filter-expression, it's captured in the first phase before the stack is unwound. You still get the full stack where the exception was thrown, but you only pay for it when necessary.
There doesn't seem to be any nice way like MSVC's exception filters, but I think at some point I saw something working on linux/libstdc++. I can't find it right now, but if I remember correctly, it involved hacking some RTTI implementation details to hook the "does the exception type match the catch-handler's type" check.
View all comments
Show parent comment
1
u/kniy Apr 20 '26
You are misunderstanding. Two-phase-unwinding first searches the stack for a matching catch-block; and then in the second phase unwinds the stack (calling destructors). By capturing the stack trace within the filter-expression, it's captured in the first phase before the stack is unwound. You still get the full stack where the exception was thrown, but you only pay for it when necessary.