G
G
Grigory Vasilkov2017-01-27 10:04:27
PHP
Grigory Vasilkov, 2017-01-27 10:04:27

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

5 answer(s)
D
DevMan, 2017-01-27
@gzhegow

architecture dependent. It's more convenient for me to immediately raise the exception.

V
Vasily Melnikov, 2017-01-27
@BacCM

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.

D
d-stream, 2017-01-27
@d-stream

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

D
dmitriy, 2017-01-27
@dmitriylanets

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.

L
leremin, 2017-01-27
@leremin

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 question

Ask a Question

731 491 924 answers to any question