0
votes
5answers
264 views

Should we only catch in exceptional circumstances?

Whether error handling by throwing exceptions is good or bad is contentious. Are exceptions as control flow considered a serious antipattern? If so, Why? The common line is that exceptions are for ...
0
votes
1answer
150 views

Is ok to throw exception in normal code path which eliminate a possible programmer error? [duplicate]

I know that exception should be thrown in exceptional case (e.g. out of memory, programmer error). For these cases, I don't need to worry about performance throwing these exception. But what happen ...
2
votes
2answers
457 views

Doing work in vector's push back

I often use the following syntax: std::vector<foo> vec; vec.push_back( someClass.getFoo(...).modifyAndReturn() ); Considered about exception safety, I quote the standard on vector's push back ...
5
votes
4answers
681 views

What's the reason exceptions are heavily used in managed (C# and Java) languages but not in C++? [closed]

AFAIK, a lot of C++ projects don't allow exceptions and deny them in coding guidelines. I have a lot of reasons, for example, exception is hard to handle correctly if your binary needs to be compiled ...
2
votes
3answers
361 views

What code lays behind C++ exception?

In C and C++ you can return a single variable inside a function. Now in the case that variable is returning data, and not an error code, you can use exceptions. But how is that possible? If you data ...
26
votes
5answers
8k views

Why is there no 'finally' construct in C++?

Exception handling in C++ is limited to try/throw/catch. Unlike Object Pascal, Java, C# and Python, even in C++ 11, the finally construct has not been implemented. I have seen an awful lot of C++ ...
0
votes
2answers
183 views

Is there anything special to consider when writing my own exception class in C++? [closed]

If I wanted to implement my own version of the std::exception for no good reason, are there any special things about implementing this kind of object that I should be aware of? It seems like a fairly ...
4
votes
4answers
521 views

Having error codes option in C++ library for performance

I have written an open source and cross-platform C++ File Library which have exception and error codes. Exceptions can be disabled when the program is running. In that case, the user have to check the ...
8
votes
5answers
911 views

“Programming error” exceptions - Is my approach sound?

I am currently trying to improve my use of exceptions, and found the important distinction between exceptions that signify programming errors (e.g. someone passed null as argument, or called a method ...
1
vote
3answers
94 views

Communicating details of method result?

I have code like this (pseudocode) foreach(Box box in boxes) { if(boxFilter.PassesFilter(box)) { // do something useful } else { Log.Log(format("Box %s was rejected", ...
8
votes
4answers
938 views

Exceptions as asserts or as errors?

I'm a professional C programmer and a hobbyist Obj-C programmer (OS X). Recently I've been tempted to expand into C++, because of its very rich syntax. So far coding I haven't dealt much with ...
25
votes
3answers
6k views

Why are exception specifications bad?

Back in school some 10+ years ago, they were teaching you to use exception specifiers. Since my background is as one of them Torvaldish C programmers who stubbornly avoids C++ unless forced to, I only ...
4
votes
2answers
541 views

Is there a term for the error-handling anti-pattern of discarding all available info and just returning failure?

From time to time (unfortunately way too often) I have to fix code such as this: // C++ code bool anyOldFunction(Param p) { try { ... if(some_condition_here) { handleErrorX(); return ...
1
vote
1answer
351 views

How does compiler handle exceptions that are implicit? Looking for design strategies

Throughout the function handleException, the exception encountered is implicit. How does the compiler handle such implicit passing of exceptions? [For e.g. in C++ methods, this pointer is passed to ...