I would like to add code in try and catch block that will throw an error in case of developer mode.

If deployment mode founds developer mode then it will throw an error in try and catch block.

If deployment mode founds production mode then it will not throw an error.


Developer mode

  • Static file materialization is not enabled.
  • Uncaught exceptions displayed in the browser
  • Exceptions thrown in error handler, not logged
  • System logging in var/report, highly detailed.

You should use the Developer mode while you are developing customizations or extensions. The main benefit to this mode is that error messages are visible to you. It should not be used in production because of its impact on performance. In Developer mode, static view files are generated every time they are requested. They are written to the pub/static directory, but this cache is not used. This has big performance impact, but any changes a developer makes to view files are immediately visible.

Uncaught exceptions are displayed in the browser, rather than being logged. An exception is thrown whenever an event subscriber cannot be invoked.

System logging in var/report is highly detailed in this mode.

Production mode

  • Deployment phase on the production system; highest performance
  • Exceptions are not displayed to the user -- written to logs only.
  • This mode disables static file materialization.
  • The Magento docroot can have read-only permissions.

You should run Magento in Production mode once it is deployed to a production server.

Production mode provides the highest performance in Magento 2.

The most important aspect of this mode is that errors are logged to the file system and are never displayed to the user. In this mode, static view files are not created on the fly when they are requested; instead, they have to be deployed to the pub/static directory using the command-line tool. The generated pages will contain direct links to the deployed page resources.

Any changes to view files require running the deploy tool again.

Because the view files are deployed using the CLI tool, the web user does to need to have write access. The Magento pub/static directory can have read-only permissions, which is a more secure setup on a publicly accessible server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.