View sourcecode

The following files exists in this folder. Click to view.

exception.php

1 lines ASCII Unix (LF)
1
<?php
error_reporting(-1);

echo "<p>Throw <a href=?standard>standard exception</a> or <a href=?extended>extended exception</a></p>";

class E extends Exception {

    function __construct($message) {
        parent::__construct($message);
    }

}


try {
    echo "<p>Preparing to throw exceptions.";
    if(isset($_GET['standard'])) {
        echo "<p>THrowing standard exception</p>";
        throw new Exception("Standard exception");
    }
    if(isset($_GET['extended'])) {
        echo "<p>Throwing extended exception.";
        throw new E("Extended exception");
    }
}
catch (Exception $e) {
    echo "<p>Caught standard exception -> ";
    echo $e->getMessage();
}
catch (E $e) {
    echo "<p>Caught extended exception -> ";
    echo $e->getMessage();
}