Answer the question
In order to leave comments, you need to log in
What is more convenient for those who have already tried it - Pass an error return or immediately throw an Exception directly from the function / foreach?
What is more convenient for those who have already tried it - Pass an error return or immediately throw an Exception directly from the function / foreach?
Answer the question
In order to leave comments, you need to log in
architecture dependent. It's more convenient for me to immediately raise the exception.
As already mentioned, it depends on the architecture.
But the most important thing is that there is a monotony of the approach and there is no hodgepodge.
Purely subjective, I prefer error returns through return. And there are several reasons for this.
Not all compilers easily digest exceptions, yes in 2017! For example, for embedded systems for DSP, in general, pure C is recommended in many places. And enabling support for exceptions and rtti is not recommended.
It basically depends on what is required.
In especially perverted cases, you can also race the results at each iteration -)
The main thing to remember about the price
Well, yes, one of the fundamental differences:
returning through return is a return to one level, and exception - to any number of levels.
those. with a hundred nested exception calls, if not, for example, try-catch will cause instant teleportation up to the operating system
throw an Exception if further execution of the function is not possible by
throwing an Exception you can handle the error depending on where you will use the functionality.
For example, in C# there are quite a few exceptions, but in Qt there are none at all. That is, both principles have the right to exist. And on the case, type in the search engine "exclusion habr or return codes" and read the articles and comments on them. There are dozens of articles and hundreds of thousands of comments.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question