5 ms·
If exit() is too abrupt, you can always use setjmp() and longjmp() to set up a non-local jump to an error handler.
by qwph 18y ago
If exit() is too abrupt, you can always use setjmp() and longjmp() to set up a non-local jump to an error handler.
- jmtulloss 18y agosetjmp/longjmp is essentially what exception handlers do for you. I love C for its simplicity, but I'm not certain that leaving exception handling out of the language was a good idea. There are a lot of people who would agree with me there, including (I believe) a few Bell labs veterans who wrote the language in the first place.
- LogicHoleFlaw 18y agoThe nice thing about exceptions beyond setjmp/lngjmp (in C++ at least) is the destructor semantics which you can use to guarantee that resources are cleaned up on error. There are better ways to handle such things, such as scoped resource allocation, but exceptions do an ok job.
- qwph 18y agoYou can actually use setjmp()/longjmp() to implement that kind of thing, it turns out. Here's but one example: http://www.on-time.com/ddj0011.htm http://www.on-time.com/ddj0011.htm I'm almost tempted to make an analogy with scheme's (call-with-current-continuation) here, but I think that might be pushing it.
- parenthesis 18y agoAgreed. I rarely exit() out of an error. I was responding to the parent's want for "a big, flashy, loud, total failure".