[OT] Error handling in C3 language
Kagamin
spam at here.lot
Thu May 29 20:18:27 UTC 2025
https://c3-lang.org/language-common/optionals-advanced/
The language is quite nice, resembles BetterC, but also the first
ergonomic language where I see the `Result` type in action.
`Result` is also used for nullable types.
```
// Function returning an Optional
fn int? maybe_func() { /* ... */ }
fn void? test()
{
// ❌ This will be a compile error
// maybe_function() returns an Optional
// and 'bar' is not declared Optional:
// int bar = maybe_function();
int bar = maybe_function()!;
// ✅ The above is equivalent to:
// int? temp = maybe_function();
// if (catch excuse = temp) return excuse?;
// Now temp is unwrapped to a non-Optional
int bar = temp; // ✅ This is OK
}
```
But striving to be evolution of C, faults look like error code
singletons and apparently don't carry much information.
More information about the Digitalmars-d
mailing list