[RFC] Throwing an exception with null pointers
Steven Schveighoffer
schveiguy at gmail.com
Tue Apr 15 02:48:42 UTC 2025
On Monday, 14 April 2025 at 15:42:07 UTC, Derek Fawcus wrote:
> On Monday, 14 April 2025 at 15:24:37 UTC, Richard (Rikki)
> Andrew Cattermole wrote:
>>
>> It is important to note that a task isn't always a process.
>> But once an event like null dereference occurs that task must
>> die.
>
> It is not the dereference which is the issue, that is the
> downstream symptom of an earlier problem. If that reference is
> never supposed to be null, then the program is already in a non
> deterministic even without the crash.
This is the exact problem. The solution proposed here just
doesn't understand what the actual problem is. Null dereferences,
and index out-of-bounds are *programming errors*. You need to fix
them in the program, not recover and hope for the best.
Trying to recover is the equivalent of a compiler resolving a
syntax ambiguity with a random number generator.
Null dereference?
1. Is it because I trusted a user value? => validate user input,
rebuild, redeploy
2. Is it because I forgot to initialize something? => initialize
it, rebuild, redeploy
3. Is it because I forgot to validate something? => do the
validation properly, fix whatever it was sending in invalid data,
rebuild, redeploy
4. Is it something else? => thank you program, for crashing
instead of corrupting everything. Now, time to find the memory
corruption somewhere.
Similar flow chart for out-of-bounds errors.
-Steve
More information about the Digitalmars-d
mailing list