Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> It is true that C++ exceptions are not checked and are rarely part of the interface signature but C++ exceptions are not a tool for general error handling

They’re literally the only way to report ctor errors.

> What Zig and Rust have as error handling mechanisms C++ has them too.

Only in the most reductive way that all langages are turing complete, in which case Java has them as well.



> They’re literally the only way to report ctor errors.

The point being? Please go find me a codebase which wraps object instantiation in try-catch clause if that's what you are trying to say. I haven't seen any.

Anyway, for that reason constructors are always written so that they cannot fail in hideous ways, and if there is no other way around it there is always 2-phase initialization (personally I think it's an anti-pattern).

> Only in the most reductive way that all langages are turing complete, in which case Java has them as well.

Nonsense. Zig AFAIU abstracts error types as some sort of integer enums while OTOH Rust has Result<T, E>. C++ has both of those mechanisms baked either into the language (enum) or standard library (std::expected, std::optional).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: