News for hackers. Stuff that matters.
Re:Current hardware trends make C++ exceptions harder to jus... by CJefferson on Tuesday February 22, 2022 @03:04PM (#30432951)
Why am I "not supposed to use exceptions"? I don't understand why exception should be used when errors occur occasionally, or when they occur 50,000/sec. They are a control flow method for when errors occur.
Re:Current hardware trends make C++ exceptions harder to jus... by michaelnik on Tuesday February 22, 2022 @06:32PM (#30435374)
I'd add a (major) inconvenience is problem investigation, often exceptions point you to root cause and all you need it to break on the first exception (think after running big codebase, for an 1h just to get where problem is), but if they are thrown willy-nilly this debugging strategy is MUCH less convenient...
Re:Current hardware trends make C++ exceptions harder to jus... by jcelerier on Wednesday February 23, 2022 @11:38AM (#30442930)
yep, it's great to just `catch throw` in gdb, launch tests, and things will stop exactly when the error happens
Re:Current hardware trends make C++ exceptions harder to jus... by MauranKilom on Tuesday February 22, 2022 @03:19PM (#30433134)
For the same reason you may want to use or not use memory allocations when doing something 1 time per second or 1 million times per second. Performance is not amenable to arguments about degree (especially when talking about this many orders of magnitude in degree).
Re:Current hardware trends make C++ exceptions harder to jus... by gpderetta on Tuesday February 22, 2022 @04:15PM (#30433915)
But again, the question is whether exceptions need to be slow.

If I'm writing a string_to_int function today I would return an optional<int> (or some Either variant). But if exceptions were cheap I would use them. If I'm catching an exception in the context of immediate caller and the compiler inlines the calle, it ought to be able to optimise the exceptional path away. But it doesn't happen.

Re:Current hardware trends make C++ exceptions harder to jus... by jcelerier on Wednesday February 23, 2022 @11:33AM (#30442886)
> . They are a control flow method for when errors occur.

no, not any errors, exceptional errors. Input data coming from "outside" being invalid is not exceptional. The filesystem suddenly becoming inaccessible during a copying or caching operation, the OS not being able to join a thread, your logging backend becoming unable to log because the disk is full, or a regular expression being incorrect are what comes to mind when I think of exceptional situations (unless your program allows users to input regexps). If your program runs on a normal computer in normal conditions, no exceptions should ever be thrown.