Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 0cf4b09

Browse files
committed
Make catching of exceptions from Fibers optional
This commit allows exceptions from Fibers to be completely uncaught thus causing a termination of the program and, depending on the configuration, creation of a core dump. An attached debugger can then be used to properly investigate the status of the program at the time of the failure.
1 parent 1e25749 commit 0cf4b09

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/core/thread.d

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,14 +3445,16 @@ private
34453445
obj.m_ctxt.tstack = obj.m_ctxt.bstack;
34463446
obj.m_state = Fiber.State.EXEC;
34473447

3448-
try
3448+
if( obj.catch_exceptions ) try
34493449
{
34503450
obj.run();
34513451
}
34523452
catch( Throwable t )
34533453
{
34543454
obj.m_unhandled = t;
34553455
}
3456+
else
3457+
obj.run();
34563458

34573459
static if( __traits( compiles, ucontext_t ) )
34583460
obj.m_ucur = &obj.m_utxt;
@@ -3863,19 +3865,21 @@ class Fiber
38633865
*
38643866
* Params:
38653867
* fn = The fiber function.
3868+
* ce = If true, exceptions will be caught and assigned to m_unhandled
38663869
* sz = The stack size for this fiber.
38673870
*
38683871
* In:
38693872
* fn must not be null.
38703873
*/
3871-
this( void function() fn, size_t sz = PAGESIZE*4 ) nothrow
3874+
this( void function() fn, bool ce = true, size_t sz = PAGESIZE*4 ) nothrow
38723875
in
38733876
{
38743877
assert( fn );
38753878
}
38763879
body
38773880
{
38783881
allocStack( sz );
3882+
catch_exceptions = ce;
38793883
reset( fn );
38803884
}
38813885

@@ -3886,19 +3890,21 @@ class Fiber
38863890
*
38873891
* Params:
38883892
* dg = The fiber function.
3893+
* ce = If true, exceptions will be caught and assigned to m_unhandled
38893894
* sz = The stack size for this fiber.
38903895
*
38913896
* In:
38923897
* dg must not be null.
38933898
*/
3894-
this( void delegate() dg, size_t sz = PAGESIZE*4 ) nothrow
3899+
this( void delegate() dg, bool ce = true, size_t sz = PAGESIZE*4 ) nothrow
38953900
in
38963901
{
38973902
assert( dg );
38983903
}
38993904
body
39003905
{
39013906
allocStack( sz );
3907+
catch_exceptions = ce;
39023908
reset( dg );
39033909
}
39043910

@@ -4173,6 +4179,13 @@ class Fiber
41734179
}
41744180
}
41754181

4182+
//
4183+
// If true, exceptions thrown inside the fiber will be caught and assigned
4184+
// to m_unhandled, otherwise exceptions will cause a termination of the
4185+
// program
4186+
//
4187+
bool catch_exceptions;
4188+
41764189
private:
41774190
//
41784191
// Initializes a fiber object which has no associated executable function.

0 commit comments

Comments
 (0)