Code Monkey home page Code Monkey logo

Comments (5)

AliverdiSultanli avatar AliverdiSultanli commented on July 30, 2024

@alexeymezenin

from laravel-best-practices.

alexeymezenin avatar alexeymezenin commented on July 30, 2024

@AliverdiSultanli I'm sorry, I don't understand the question.

from laravel-best-practices.

AliverdiSultanli avatar AliverdiSultanli commented on July 30, 2024

@alexeymezenin How we can write code about throw exception with best practice? With try catch or another style?

from laravel-best-practices.

alexeymezenin avatar alexeymezenin commented on July 30, 2024

Laravel automatically converts some types of exceptions to appropriate HTTP errors which is great because we don't need to handle those. With other types of exceptions just use standard try/catch.

from laravel-best-practices.

devrkd avatar devrkd commented on July 30, 2024

There few things which can improve your code while dealing with exceptions.

  1. Always throw specific exceptions, rather than generic Exceptions, and if it's related to HTTP, add status code as well.
  2. Though application-specific exceptions can easily be caught by the simple catch statement with that specific exception type, however, if you dealing with some data dependent on an external source, you might want to also catch Throwable, this will allow you to capture exception like missing array index, and help you to log later the exception to an external system like sentry.
  3. Use finally, with try catch statement, it will help you to execute some cleanup stuff.

from laravel-best-practices.

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.