What is exception handling in PHP

| Last Updated: | In: Core php


Exception handling is used to change the normal flow of the code execution if a specified error (exceptional) condition occurs. This condition is called an exception.

An exception can be thrown, and caught (“catched”) within PHP. Code may be surrounded in a try block, to facilitate the catching of potential exceptions. Each try must have at least one corresponding catch block.

exception

We will show different error handling methods:

Basic use of Exceptions
Creating a custom exception handler
Multiple exceptions
Re-throwing an exception
Setting a top level exception handler

Principles of exceptions

Code may be surrounded in a try block, to help catch potential exceptions
Each try block or “throw” must have at least one corresponding catch block
Multiple catch blocks can be used to catch different classes of exceptions
Exceptions can be thrown (or re-thrown) in a catch block within a try block

The basic syntax

Complete Example of php exception handling

I hope this will help you. If you like this article, do like & share it with your friends on social media. Don’t forget to follow us on Facebook and Twitter to learn cool tutorials.

Tags: , , , , , , , , , , ,


About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby.


You may also like:

Follow us!

Get Free Access of 380+ Scripts

Don't worry you'll not be spammed!

Featured eBook

WordPress Security Guide

Free Guide: Learn how to implement security guideline in your WordPress site...

DOWNLOAD

Pincode Finder

pincode-finder tool

Online Pincode Finder

Best tool to locate post Office address and pincodes of all india...

SEARCH NOW
Copyright © 2013-2017