L
L
ldmitriy2020-06-07 13:22:58
C++ / C#
ldmitriy, 2020-06-07 13:22:58

Is this an exception or an error?

Why can't the term exception be replaced by an error?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir Korotenko, 2020-06-07
@ldmitriy

Here it is chewed up.
https://stackoverflow.com/questions/912334/differe...
In fact, exceptions are errors, but we can process some, we break on others.
For example, WebException is predictable in principle, I have a lousy channel and I try again, FormatException outputs something to the log.
I simply extinguish everything at the application level so as not to destroy it, write it to the log and offer the user a button to scold me or try again .
UPD
Most importantly, I forgot
https://docs.microsoft.com/ru-ru/dotnet/standard/e. ..

F
freeExec, 2020-06-07
@freeExec

Well, what's my mistake if you make me divide by zero? Or are you asking me to open a file that you didn't create for some reason? Or so scored the memory that I did not have enough? Therefore, I inform you about an exceptional situation, the consequences of which you need to rake, and not me - a normal function. Perhaps this is your mistake. And my code works fine.

A
Alexander Yudakov, 2020-06-07
@AlexanderYudakov

Error (bug) - there are no exceptions here:

decimal Умножить(decimal множитель1, decimal множитель2)
{
    // программист перепутал операторы
    return множитель1 + множитель2;
}

Mistakes are allowed, found and corrected.
Exception (exception) - there are no errors here:
string ReadFileTextUtf8(string fileName)
{
    if (String.IsNullOrEmpty(fileName))
        throw new ArgumentNullException("fileName");

    return File.ReadAllText(fileName, Encoding.UTF8);
}

Exceptions are thrown (throw) and processed (handle) - using catch (selective processing) or finally (final processing).
In order to avoid confusion, it is better not to use the English "error" at all. As a rule, people who use "error" don't understand what they are talking about.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question