What is exception handling in PHP

In this article I am going to explain about PHP exception handling.
  • 2063

Exception handling in PHP

Exception is an event that occur during the execution of program and disturbs the normal flow of program and exception handling is used to solve these problems.

Coding up an exception

In this part we will describe the basic idea of exception. To handle possible error conditions you will divide your program into a number of block of thee different type:

  • Try

    In this block exception is occurred.
     
  • Catch

    Catch blocks contains the code that deals with various error conditions.
     
  • Finally

    Finally block is always executable in both condition, whether error is come or not.

Example of  exception handling

<html>

<body>

<?php

    try {

if(1==1)

{

throw new Exception("ok");

}

    }

catch(Exception $exception) {

        print "Exception is occured!\n";

    }

?>

<body>

<head>


Output:

exception handlinf.jpg
You may also want to read these related articles :here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2019 DotNetHeaven. All rights reserved.