GithubHelp home page GithubHelp logo

Comments (1)

MrDave1999 avatar MrDave1999 commented on June 19, 2024

Exceptions were designed to report unexpected errors immediately to developers (or programmers). In this context, an unexpected error is a situation that should never have occurred, i.e. it is not part of the normal execution of an application.
When this type of situation occurs, the developer must fix it immediately, in some cases they are bugs that need to be corrected from the source code, in other cases they are errors that must be corrected from a configuration file (for example, specifying the connection string correctly).

For that reason, an exception object includes valuable information for the developer as support when correcting an unexpected error:

  • Exceptions contain a property named StackTrace. This string contains the name of the methods on the current call stack, together with the file name and line number where the exception was thrown.
  • Exceptions contain a property named Message. This string contains a message explaining the reason for the exception.
  • See more properties.

Knowing this, it can be deduced that the exceptions are closely related to the developer, it facilitates the programming too much and allows him to know immediately the cause of the unexpected error.

That is why it does not make sense to use exceptions for expected errors, which are part of the execution of the application, it is normal that they happen and that does not prevent the application to continue working without any problem.
For example, let's imagine that a normal user does not enter the username and email address.
These fields are required, should I throw an exception?

In that case it makes no sense to throw an exception, it is an error caused by the end user, it has nothing to do with the developer, therefore, the valuable information contained in an exception object, especially the stack trace, will remain unused if I decide to throw an exception for that situation.
In fact, it is completely normal for that error to happen, it is something I would expect to happen.

from simpleresults.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.