4 ms·
Yeah, but in C++ you get people ignoring exceptions too. I'm fine with return codes, I don't mind them even though exceptions are maybe a little bit better.
by jacobush 7y ago
Yeah, but in C++ you get people ignoring exceptions too. I'm fine with return codes, I don't mind them even though exceptions are maybe a little bit better.
- swsieber 7y agoTrue, but in this case, ignoring an exception would be better than ignoring a return code, right? It prevent you from accidentally sending a signal to -1 (e.g. all the processes you can). The danger here with the return code is that the return code value is a valid (but not intended) input to another function that normally uses the normal return value.
- jacobush 7y agoTrue, I guess just this example didn't jive with me. I'd never dream of ignoring the return code of fork(). Some other call I don't respect enough would probably bite my ass, though.
- oconnor663 7y agoIt's not just a question of whether you did the right thing when you wrote the code. Code gets refactored and moved around, maybe by people less experienced than the original author, or maybe just by the original author when they're tired or after they've forgotten the context. Wrapper functions get defined, libraries get updated, and support gets added for new platforms. Each of those changes is an opportunity to accidentally stop checking the return code.
- akavi 7y agoHence why `Result` is really valuable. Can't ignore it (plus, the semantics are straightforward)
- thestoicattack 7y agoIf by ignoring, you mean non catching anything, I'm often okay with that. If an exception makes it top-level, you'll get a std::terminate and be done. The "canonical" example people use a lot is std::bad_alloc. Often, there is no point in catching it -- what cleanup or fallback work are you planning to do when you can't even allocate memory? Of course, silently swallowing exceptions with an empty catch-block is terrible.
- masklinn 7y agoIf you ignore (as in fail to handle) an exception, your software dies safely, it won't do the wrong thing. If you ignore or misuse error code, you carry on in a corrupted state.
- icedchai 7y agoHave you seen old java code that has tons of empty try / catch blocks? It is very, very common.
- lolc 7y agoJava is special in this regard because the common case of letting an exception terminate the program is harder than ignoring it. When I was still writing Java, I'd gotten so annoyed by this that in the top layers every method "throws Exception". It was less verbose than promoting all the checked exceptions to runtime errors. Unfortunately people don't know about this possibility and write empty catch statements because "it's not going to happen anyway". Yeah right.
- jcelerier 7y ago> Yeah, but in C++ you get people ignoring exceptions too ... and then you can just do `coredumpctl gdb` and start debugging right where things went wrong ?