Earlier quoted context omitted.
>If the API is that a function is infallible and then I decide that it’s a fallible function then that’s a pretty major change and I’m just gonna have to update all the call sites to deal with a fallible return result. What if you don't control those call sites? >Might as well just call std::abort. Sure. I mean, not really, because the caller cannot handle an abort. You're making a decision for the caller that the si…
> What if you don't control those call sites? If I am choosing to change the API contract then someone who wants to use the new API has to update. This is not a big deal. > If the function doesn't use exceptions for normal error conditions, then no, it's not a new contract I disrespectfully and emphatically disagree. I do not accept your definition of contract. > You could do something like (try-catch wrapper) Let me…
Throwing lets you handle the new situation without changing the API at all.
>Let me be clear. Having to add a bunch of random fucking try-catch bullshit around every fucking function call is EXACTLY why I hate exceptions and is EXACTLY what I think is bad software design.
See, that's what happens when you form your opinions on half-digested ideas. Let me be clear. You don't add "a bunch" of try-catch blocks. You don't wrap every call that's capable of failing exceptionally in a try-catch block. That's exactly how you don't use exceptions. The whole point of exceptions is that the compiler will handle the stack unwinding for you so you don't need to worry about it. If you don't want to, or don't know how, or can't handle an exception at a specific point then don't. Let it bubble up for someone else to catch. See the ellipsis in my example? Inside of it you might have a gigantic call tree that performs all sorts of different operations that may all fail in different and unexpected ways. You could write the whole thing and not have a single try-catch besides the one I wrote explicitly. Let me reiterate; this is what you DON'T do:
try{
foo();
}catch (...){
return Error1;
}
try{
bar();
}catch (...){
return Error2;
}
try{
baz();
}catch (...){
return Error3;
}
The only reason you would do something like this is to satisfy a specification such that you have to return different errors, specifically when each of the different calls fails. So... don't specify your functions such that you're required to do this? Just do foo();
bar();
baz();
or if you really must not throw from the function, try{
foo();
bar();
baz();
}catch (...){
return SomethingFailed;
}
TL;DR: Instead of bitching about exceptions, learn how to use them properly.