but for what I call "pseudo-embedded" that isn't really embedded, like Raspberry Pi, you can just use a bog standard ARM C++ cross-compiler with all the bells and whistles
This question attempts to collect the few pearls among the dozens of bad C++ books that are published every year.
Unlike many other programming languages, which are often picked up on the go from tutorials found on the Internet, few are able to quickly pick up C++ without studying a well-written...
the norm is that up in the main rendering loop you have a try/catch for everything you had no way of "properly" handling and then show the user an error message instead of outright crashing
@enderland um, no, that was about someone marching in and calling everyone (well, in this case, calling gnat) "rude" and "snobby". read more carefully before attacking me please. use your moderator brain!
yes all that stuff is relevant to exception safety but I think we have to convince @bigcodeszzer that exceptions have a point before talking about exception safety makes any sense
exceptions, like a properly structured program design, may be the sort of thing that's hard to grok the purpose of until you actually write a full-scale, uncontrived program for the first time
But being forced to use c++ (Cause otherwise I Would never have learned it at all) definately made me better at doing things that would have otherwise never practiced
the uni stuff is valuable not for the actual languages you learn but for the computer science background stuff on language design and compiler implementations and algorithm analysis and whatnot
@enderland Actually, on reading your message again, I'm very annoyed by it. I haven't "trolled" anyone. Actionless? Why would I start moderating a site whose moderation rules I disagree with? I've said that before, too. Though I do help you close and delete obviously bad questions. So what's your problem? Why do you feel the need to "come at me" like this? You're a moderator; you should know better. Please delete your remarks or at the least refrain from making them in the future. Thanks.
That's three times now. Next time I'll be forced to flag.
this conversation is a good example of what happens when you use error codes instead of exceptions; all the code is about propagating codes instead of doing anything useful
@bigcodeszzer because the try can be placed higher up the call stack if we want, and the actual throw inside have() might be much farther down the call stack than it looks
obviously in the one-line psuedocode it's not, as previously mentioned
@bigcodeszzer if you mean me, I was responding to your claim that using exceptions means "try/catch blocks everywhere" which as I just said is not at all true
if file cannot be opened then it should already have thrown an exception. you don't even get to lowerstackfunction()
the caller can then handle that exception, potentially with the same code that handles other exceptions, some of which may come from within lowerstackfunction
that's the whole point of new, delete, constructors, and destructors, almost all allocation/deallocation code gets called for you by the language when it should be called so you don't have to waste time figuring it out
the whole point of objects having destructors is so that their cleanup code gets called automatically when needed, so you don't have to keep track of when you need to call it
that means that everybody's destructors get called whether the function exits normally or whether the function exits prematurely due to an exception getting thrown
and if you'd written auto tempvariable = std::make_unique<sometype>() instead then you wouldn't need to worry about that variable any more, whether you get an exception or not. as it is now, you're leaking that memory because you didn't delete it. so even with this trivial example, you've already got a terrible bug caused by your most-effort approach.
as Barry said, using RAII classes like smart pointers ensures everything would get cleaned up properly without you even having to think about these things