| ▲ | WalterBright 4 hours ago | |||||||||||||||||||||||||||||||
It's been a while since I looked at Zig. I couldn't say anything intelligent about it without some study. I used to be a big fan of C++ exceptions, but eventually soured on it for various reasons. Here's an article partially addressing it from a while back: | ||||||||||||||||||||||||||||||||
| ▲ | germandiago 2 hours ago | parent [-] | |||||||||||||||||||||||||||||||
I think there is nothing better than exceptions + RAII for error handling since exceptions cannot be ignored by accident. I would classify D's scope exit/failure/success as RAII actually, even if D uses a GC. Sometimes you might not need exceptions and something like std::expected or optional is better. In my case I use expected for some network APIs since I expect failures to happen out of my control aspart of the flow of my program, but I do not see why I would not use exceptions in many other situations, such as for non-ignorsble errors. I could think of a lack of disk space or some other fatal error thst is not under the control of the program. If you forget to handle this, the error will cascade. Also, exceptions do not make the signature of a function change (at least not in C++, Java checked exceptions is different). This means that the plasticity for adding errors at any depth of the call stack augments without bypassing any error silently. All in all, I would say exceptions should be the main mechanism in normal circumstances and for expected errors you csn use error/result types. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||