On Saturday, July 8, 2023 at 12:37:24 AM UTC+8, Öö Tiib wrote:
> On Friday, 7 July 2023 at 17:23:36 UTC+3, wij wrote:
> > I just skimmed the "Error handling" section of
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines
> > It is really blink-talk, all the time till now. It read to me (just one point):
> > Because error is rare, so throw it (and forget) is justified.
> > I say practical codes have to written for all possible branches, rare or not
> > is not an issue. Take a basic example of reading an integer from the standard
> > input for instance:
> >
> > int num;
> > std::cin >> num;
> >
> > Of course, this piece is mostly for demo.
> >
> It is unclear what you mean by that example. Yes, majority of software
> does not communicate reading text from standard input using C++ streams.
Yes, not majority, but not few programs communicate through fd=0,1,2.
> > But what if we want practical codes
> > to read an integer from the standard input? I think the answer is 'no way' for
> > application developers.
> >
> Why you think so? The C++ streams can be and are useful. Just not always.
I might understand what you mean. As I know, C++ stream I/O is compatible with
C stream I/O. Many system commands rely on it. Applications use it for
convention reasons but not limited. Not fit, don't use it.
> > stdc++ library developers keep playing blind and cheat.
> > One possible reason, stdc++ is for checking and demo. the feature of C++
> > itself, not really for application developer.
> >
> You mean GNU C++ library implementers? On the contrary ... most contributors
> are rather good and well paid C++ developers. They manage to implement
> what standard requires and quite well IMHO.
Let say "E.3: Use exceptions for error handling only", a section in the link above.
The statement is stronger than before. But, what do general people read, while
the real meaning keeps changing? (I mis-read the file CppCoreGuidelines and
example program) ...So, in the end, I think the meaning of 'error' depends.
IMO, error reports (of a function) are just info. for caller to branch execution
path. Throwing (setjmp/longjmp) error, in general, will lose the error context.
Application will have less confident what is really caught to choose preciser action.
The result is larger portion of the program is 'reset'.
(By the way, I think error report by errno might not be bad, also practical)