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

Commit 3d045c5

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 3d045c5

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/core/thread.d

Lines changed: 17 additions & 4 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;
@@ -3864,18 +3866,20 @@ class Fiber
38643866
* Params:
38653867
* fn = The fiber function.
38663868
* sz = The stack size for this fiber.
3869+
* ce = If true, exceptions will be caught and assigned to m_unhandled
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, size_t sz = PAGESIZE*4, bool ce = true ) nothrow
38723875
in
38733876
{
38743877
assert( fn );
38753878
}
38763879
body
38773880
{
38783881
allocStack( sz );
3882+
catch_exceptions = ce;
38793883
reset( fn );
38803884
}
38813885

@@ -3887,18 +3891,20 @@ class Fiber
38873891
* Params:
38883892
* dg = The fiber function.
38893893
* sz = The stack size for this fiber.
3894+
* ce = If true, exceptions will be caught and assigned to m_unhandled
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, size_t sz = PAGESIZE*4, bool ce = true ) nothrow
38953900
in
38963901
{
38973902
assert( dg );
38983903
}
38993904
body
39003905
{
39013906
allocStack( sz );
3907+
catch_exceptions = ce;
39023908
reset( dg );
39033909
}
39043910

@@ -4017,7 +4023,7 @@ class Fiber
40174023
* fibers that have terminated, as doing otherwise could result in
40184024
* scope-dependent functionality that is not executed.
40194025
* Stack-based classes, for example, may not be cleaned up
4020-
* properly if a fiber is reset before it has terminated.
4026+
* properly if a fiber is reset before it has terminated.
40214027
*
40224028
* In:
40234029
* This fiber must be in state TERM or HOLD.
@@ -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)