Throw stack trace from program kill

Steven Schveighoffer schveiguy at gmail.com
Sun Jan 16 18:42:21 UTC 2022


On 1/16/22 1:33 PM, Paul Backus wrote:

> It worked when I tested it,

Yeah, but your example is designed specifically to only encounter the 
signal in one specific spot (inside a D function).

> but I'm not sure how reliable it is. A more 
> conservative implementation would be something like
> 
> ```d
> extern(C) void handleCtrlC(int)
> {
>      import core.stdc.stdlib: exit;
>      import std.stdio: writeln;
> 
>      try throw new Exception("Killed by CTRL+C");
>      catch (Exception e)
>      {
>          writeln(e.message);
>          writeln(e.info);
>          exit(1);
>      }
> }
> ```

This too is not going to be a good idea. writeln(e.info) is going to 
possibly start allocating. A signal can come at any time, even when 
locks are held or things are in an intermediate state.

I use Adam's approach normally -- set a flag and act on it later.

-Steve


More information about the Digitalmars-d-learn mailing list