I've always found C++'s "trend" of handling normal or non-exceptional system errors with exceptions lackluster (and I'm being charitable). Overall trimming things down to (basically) passing around a couple integers and telling the user to check their manual is much better, much less error prone, and much more efficient and deterministic.

16 Comments
SpaceNoodle@lemmy.world · 12 pts · 342d
Use an enum class, it's strongly typed but the compiler just treats it as an integer
lambalicious@lemmy.sdf.org · 8 pts · 342d
Yeah they are quite good and they do basically fall under "just wrap an integer".
benni@lemmy.world · 3 pts · 342d
Same, I also like giving this the [[nodiscard]] attribute if I want to make sure that it's not ignored.
SpaceNoodle@lemmy.world · 4 pts · 342d
-Wunused-resultis good practice in generalbenni@lemmy.world · 2 pts · 342d
I'm mixed on this one, because sometimes you'll want to call a function for its side effects without caring about the return value. E. g. container methods returning an iterator that shows you where the side effect took place.
SpaceNoodle@lemmy.world · 3 pts · 342d
Right, so just cast the returned value to void:
(void)function();mercator_rejection@programming.dev · 3 pts · 339d
The new C++ way is
SpaceNoodle@lemmy.world · 1 pts · 339d
Neat, I learned something. I keep smashing C and C++ together on my head.
The notes on that page do suggest the same method I did, however.
lambalicious@lemmy.sdf.org · 0 pts · 338d
First: it's not new, it's been around since C++03.
Second... it's not even that great. It's more characters to type and you have to deal with
stds and colons.(void)is a classic and works everywhere.But hey, at least it's not
static_cast<void>(...).benni@lemmy.world · 2 pts · 342d
Cool, I didn't know that was a thing 👍
ulterno@programming.dev · 7 pts · 341d
QSqlErrorin my functions and point the user toQSqlErrordocumentation in QtF1at any time in Qt Creator to get the help pageboolreturn value (I am sitting 10m away in the same room as the client. Senior management is in another state)F1on their computer and show the userbool QSqlError::isValid()boolresult.isValid()in anifstatement.booldeleteDocumentfunction is deleting the document but returning false.Yes, they called
deleteDocumenton the same ID twice.BTW, I did create a manual with usage examples.
A few months later, a senior engineer on the client side checks their code and tells me to
throwexceptions for everything, because half of the time, the user-devs are not checking theQSqlErrorreturn values.From what I remember, that gives a warning an not an error.
The clients' code already has >400 warnings^[edit: fixed wrong word] on every build. They won't care
lambalicious@lemmy.sdf.org · 2 pts · 338d
Yeah,
[[nodiscard]]throws a warning (that's half the point of attributes, anyway).marcos@lemmy.world · 3 pts · 342d
For fuck's sake people, stop localizing your error messages.
lambalicious@lemmy.sdf.org · 3 pts · 342d
I have no problem with localizing error messages... I just think an error handler is the absolutelest wrong place to do it. Localize it in the manual. Appendix C page 3, "Spanish / Español". Error routines should print machine-readable information. A couple numbers. Maybe a smiley (or, given the context, frownley).
dreugeworst@lemmy.ml · 3 pts · 342d
as long as people are logging pertinent information sure. but I've had the misfortune of working with plenty of programs that return just an error code that means 'something went wrong initialising subsystem X' and left it all to the user to figure out what exactly went wrong, with files and where in those files etc. etc.
mercator_rejection@programming.dev · 2 pts · 342d
At work we literally just went through this yesterday, just with
folly::Expected. A new guy joined the team and wanted to propose we update how we handle errors.