How we use exceptions in our web development services applications?

Tip of the week

Created on: November 11, 2017

Updated on: November 11, 2017

How we use exceptions in our web development services applications?

I am sure most of you who have used computer applications have experienced an exception or a blue screen of death on a windows machine. These exceptions happen from time to time and they are used by developers as a marker so that data is collected and used for troubleshooting purposes.

The best developers in the development paradigm use exceptions as a means to learn from them and they are an integral part of the web development services process, and we will delve in to it further in the next section.

What is an exception?

An exception is according to Wikipedia the process of responding to the occurrence, during computation, of exceptions - anomalous or exceptional conditions requiring special processing this changes the normal flow of execution within a program.

You can think of exceptions as being break points within your code that is designed to halt the normal flow of a computer program, be it an in house project or web development services based.

Exceptions within a Laravel app

We use Laravel to build our applications, we also use the following platforms Craft CMS and Wordpress.

If you check out the exception screenshot listed below:

Picture containing a single exception

Our HttpNotfound exception inherits from an abstract class and in this case our abstract class is called \Exception.

The Handler deconstructed

The handler is the central place in which all of our exceptions are handled.

dontreport method

If you take a look at the handler-dontreport image below:

Picture containing the don’t report method

You will notice that there are a number of exceptions that are not reported within the application. These are listed in an array.

report method

Picture containing the report method

Within the above image we have a report function and this is where the Exception class is injected in to our function.

The list that is injected excludes the don’t report function list of exceptions.

render method

Picture containing the render method

And finally we have the exception render function. This displays a list of each exception together with the views that are displayed if the exception is triggered.

So for example with have the MethodNotFoundException and this invokes the 403 view.

Notice that all of the exceptions listed point to an errors folder.

The errors folder contains the list of views that are invoked in the event of an exception being thrown.

Where are our customised error views stored?

Picture containing the error view

If you go to resources/views/errors our views are stored here and you are free to design a view to suit your own needs.

That concludes today's post about exceptions where we learn't what an exception is and how to customise your own exception.

Stay tuned for further tips and tricks from The link also provides information about the web development services we offer.