www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - You can call Fiber.yield() inside a vectored exception handler (win32)

In case anyone was wondering, in 32-bit Windows you can call 
Fiber.yield() from inside a vectored exception handler, and 
subsequently resume the fibre again.
As far as I can tell it works flawlessly.

Here's a little example:


extern(Windows) int on_exception_global(EXCEPTION_POINTERS* X) 
nothrow {
	/* once installed, this function will be called for every
	exception raised in the current process */

	if (X.ExceptionRecord.ExceptionCode == STATUS_ACCESS_VIOLATION) {

		Fibre.yield(); // can do!

		// retry the instruction that raised the exception

	// call next exception handler

auto Hdl = enforce(AddVectoredExceptionHandler(
	1, /* insert at front of exception-handler chain */


Careful about throwing from inside your exception handler (any 
kind of software or hardware exception, not limited to 
'Throwable'). Don't want to end up in an infinite loop.
Aug 31 2016