[RFC] Throwing an exception with null pointers

Atila Neves atila.neves at gmail.com
Wed Apr 16 08:18:41 UTC 2025


On Monday, 14 April 2025 at 14:22:09 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
> On 15/04/2025 1:51 AM, Atila Neves wrote:
>> On Saturday, 12 April 2025 at 23:11:41 UTC, Richard (Rikki) 
>> Andrew Cattermole wrote:
>>> I've been looking once again at having an exception being 
>>> thrown on null pointer dereferencing.
>>> However the following can be extended to other hardware level 
>>> exceptions.
>>>
>>> [...]
>> 
>> I would like to know why one would want this.
>
> Imagine you have a web server that is handling 50k requests per 
> second.
>
> It makes you $1 million dollars a day.
>
> In it, you accidentally have some bad business logic that 
> results in a null dereference or indexing a slice out of bounds.

Possible mitigations:

* Use `sigaction` to catch `SIGSEGV` and throw an exception in 
the handler.
* Use a nullable/option type.
* Address sanitizer.
* Fuzzing the server (which one should do anyway).

How is out of bounds access related to null pointers throwing 
exceptions?

> How likely are you to keep using D, or willing to talk about 
> using D positively afterwards?

People write servers in C and C++ too.



More information about the Digitalmars-d mailing list