RFC: Change what assert does on error

Timon Gehr timon.gehr at gmx.ch
Sun Jun 29 22:33:08 UTC 2025


On 6/29/25 23:44, Derek Fawcus wrote:
> On Sunday, 29 June 2025 at 18:04:51 UTC, Richard (Rikki) Andrew 
> Cattermole wrote:
>> What a couple of us are suggesting is that we change the default 
>> behaviour from ``throw AssertError``.
>> To: ``printBacktrace; exit(-1);``
> 
> I have no issue with the suggestion.
> 
> I simply note that on posix systems, the return value usually gets mask 
> to 8 bits, so the above is identical to exit(255).
> 
> DF

That particular aspect actually would be an improvement I think. One of 
the cases where I am catching `Throwable` is just:

```d
try{
     ...
}catch(Throwable e){
     stderr.writeln(e.toString());
     import core.stdc.signal:SIGABRT;
     return 128+SIGABRT;
}
```

This can be useful to distinguish assertion failures from cases where my 
type checker frontend just happened to find some errors in the user code.

It's a bit weird that an `AssertError` will give you exit code 1 by 
default. I want to use that error code for different purposes, as is 
quite standard.


More information about the Digitalmars-d mailing list