Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/core/thread.d
Original file line number Diff line number Diff line change
Expand Up @@ -3445,14 +3445,16 @@ private
obj.m_ctxt.tstack = obj.m_ctxt.bstack;
obj.m_state = Fiber.State.EXEC;

try
if( obj.catch_exceptions ) try
{
obj.run();
}
catch( Throwable t )
{
obj.m_unhandled = t;
}
else
obj.run();

static if( __traits( compiles, ucontext_t ) )
obj.m_ucur = &obj.m_utxt;
Expand Down Expand Up @@ -3864,18 +3866,20 @@ class Fiber
* Params:
* fn = The fiber function.
* sz = The stack size for this fiber.
* ce = If true, exceptions will be caught and assigned to m_unhandled
*
* In:
* fn must not be null.
*/
this( void function() fn, size_t sz = PAGESIZE*4 ) nothrow
this( void function() fn, size_t sz = PAGESIZE*4, bool ce = true ) nothrow
in
{
assert( fn );
}
body
{
allocStack( sz );
catch_exceptions = ce;
reset( fn );
}

Expand All @@ -3887,18 +3891,20 @@ class Fiber
* Params:
* dg = The fiber function.
* sz = The stack size for this fiber.
* ce = If true, exceptions will be caught and assigned to m_unhandled
*
* In:
* dg must not be null.
*/
this( void delegate() dg, size_t sz = PAGESIZE*4 ) nothrow
this( void delegate() dg, size_t sz = PAGESIZE*4, bool ce = true ) nothrow
in
{
assert( dg );
}
body
{
allocStack( sz );
catch_exceptions = ce;
reset( dg );
}

Expand Down Expand Up @@ -4173,6 +4179,13 @@ class Fiber
}
}

//
// If true, exceptions thrown inside the fiber will be caught and assigned
// to m_unhandled, otherwise exceptions will cause a termination of the
// program
//
bool catch_exceptions;

private:
//
// Initializes a fiber object which has no associated executable function.
Expand Down