Any way to peek at the exception currently being thrown?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jun 4 22:28:02 UTC 2021


On Fri, Jun 04, 2021 at 06:06:32PM -0400, Steven Schveighoffer via Digitalmars-d wrote:
[...]
> Honestly though, stack unwinding is black magic to me. I don't know
> how it works, but I'm pretty sure it worked before TLS was a thing in
> D.

AFAIK, stack unwinding happens on the runtime stack, which is TLS
(because each thread by definition has its own stack).  It's not *that*
magic; it's just done at a lower level than usual language constructs.

It basically consists of starting with the current stack pointer
(pointing to the top of the stack) and popping off stack frames until it
finds a stack frame that registered a catch block.  At each stack frame,
it runs any dtors that may be present in the frame in order to clean up
any local objects that need destruction.

Where the reference to the exception object is held during this process
is generally implementation detail, but I'd expect it would be either in
CPU registers or else in TLS somewhere, since it wouldn't make sense for
other threads to be able to stomp on an exception-in-flight
(accidentally or otherwise).


T

-- 
This sentence is false.


More information about the Digitalmars-d mailing list