9 ms·
No? You could just enforce invariants by panicking, which is what the C linux kernel already does.
by jeffbee 5y ago
No? You could just enforce invariants by panicking, which is what the C linux kernel already does.
- bregma 5y agoHow would a "panic" differ from an "exception"? Keep in mind what happens in C++ if you do not catch an exception.
- jeffbee 5y agoExactly my point.
- loeg 5y agoIf you allow exceptions, people try to catch them.
- mgaunard 5y agoyou'd catch and handle the exception at the adequate point inside your subsystem. The same argument could be made with return values: what happens if you don't handle them and just panic on them.
- woodruffw 5y agoLinux tries pretty hard to use panics as an absolute last resort: there are a lot of invariant failures that are better handled by disabling drivers or subsystems, marking an impossible response as illegal and just trying to muster on, etc. Having exception-worthy invariants become panics would probably be a nightmare, at least for idiomatic C++: every nontrivial ctor (including copies and moves) might be a panic site.