Re:Current hardware trends make C++ exceptions harder to jus...
by whatshisface on Tuesday February 22, 2022 @04:16PM
(#30433917)
When something happens that violates your assumptions about your own program's behavior, throwing it into a state where it doesn't know what happens next. Kind of like a panic.
[ Parent
| on HN ]
Re:Current hardware trends make C++ exceptions harder to jus...
by foldr on Tuesday February 22, 2022 @04:20PM
(#30433979)
This would mean that attempting to open a file that doesn't exist shouldn't throw an exception. But that is exactly what it does in the standard libraries of many languages with exceptions.
Re:Current hardware trends make C++ exceptions harder to jus...
by spc476 on Tuesday February 22, 2022 @05:53PM
(#30435033)
It should be up to the application to throw or not, not a library. I write a system service. If it can't find the configuration file, it can't continue, so it throws an exception. If it can't open a file that contains state from a previous run (maybe because it's the first time it's running) that's fine, the program can run without it and thus, no exception.
Re:Current hardware trends make C++ exceptions harder to jus...
by jcelerier on Tuesday February 22, 2022 @04:42PM
(#30434290)
Not in C++ I believe ?
Re:Current hardware trends make C++ exceptions harder to jus...
by TheMonarchist on Tuesday February 22, 2022 @06:23PM
(#30435303)
Re:Current hardware trends make C++ exceptions harder to jus...
by YATA0 on Friday February 25, 2022 @01:49AM
(#30464346)
That is manually throwing an exception if the file doesn't exist.
C++ stdlib does not throw an exception if a file does not exist. I agree with this philosophy because files not existing isn't an exceptional case.
Re:Current hardware trends make C++ exceptions harder to jus...
by jcelerier on Wednesday February 23, 2022 @03:04AM
(#30438789)
Damn, in all those years I've absolutely never come across this, thanks
Re:Current hardware trends make C++ exceptions harder to jus...
by foldr on Tuesday February 22, 2022 @05:22PM
(#30434727)
The C++ standard IO library doesn't enable exceptions by default, but IIRC that's just a relic of the fact that it dates back to when C++ didn't have exceptions.
Re:Current hardware trends make C++ exceptions harder to jus...
by mpyne on Tuesday February 22, 2022 @05:23PM
(#30434733)
It's library dependent. iostreams (part of C++ std lib) doesn't throw exceptions by default but I believe it can be configured to throw if you want.