3 ms·
> You wouldn't say C "has exceptions" would you? Maybe that's just me, but I wish more people would say that C "has exceptions", if only because longjmp/setjmp
by dureuill 4y ago
> You wouldn't say C "has exceptions" would you?
Maybe that's just me, but I wish more people would say that C "has exceptions", if only because longjmp/setjmp[0] interacts with exception systems of other languages, sometimes badly.
That being said, I think an important difference is that in C setjmp/longjmp do not "unwind" objects, due to the lack of destructors.
However panics at least in Rust are just exceptions by another name. The difference solely comes from culture. Even the fact that unwind can be turned to abort is not significant, considering that pretty much all production implementations of C++ have fno-exceptions
[0]: https://learn.microsoft.com/en-us/cpp/cpp/using-setjmp-longjmp?view=msvc-170 https://learn.microsoft.com/en-us/cpp/cpp/using-setjmp-longj...
- IshKebab 4y ago> That being said, I think an important difference is that in C setjmp/longjmp do not "unwind" objects, due to the lack of destructors. I don't think that is a requirement of exceptions. It's just a sensible thing that most implementations do. > The difference solely comes from culture. Maybe, but that is a huge difference! You can implement anything in any Turing complete language but you wouldn't say that they all "have" every feature... To quote https://doc.rust-lang.org/std/panic/fn.catch_unwind.html https://doc.rust-lang.org/std/panic/fn.catch_unwind.html : > It is *not* recommended to use this function for a general try/catch mechanism. The Result type is more appropriate to use for functions that can fail on a regular basis. Additionally, this function is not guaranteed to catch all panics, see the “Notes” section below.