| |
 | Posted by monkyyy in reply to Brother Bill | Permalink Reply |
|
monkyyy 
Posted in reply to Brother Bill
| On Saturday, 2 August 2025 at 20:29:22 UTC, Brother Bill wrote:
> From page 233 of "Programming in D".
import std.stdio;
import std.exception;
void main() {
MyClass variable;
use(variable);
}
class MyClass {
int member;
}
void use(MyClass variable) {
writeln("variable: ", variable);
try {
writeln(variable.member); // ← BUG
} catch (Exception ex) {
writeln("Exception: ", ex);
}
}
Why does this run, but not display expected null reference exception?
Not all errors are exceptions, Expection is just a class in the std, and then theres Error which is "more important" and catch(Error) gets you some extra cases, you can define your own. etc.
For most cases of try to do anything someone had to write a literal Throw
but I think the os kills you before you even passed something to writeln. Fundmentally youd have to have every access of a class be null checked, which I bet people want, but must not be part of the 30 year old c compiler that d comes from.
|