ADS - GoldenWeb.it Directory "Premium" Links

Bet365 bookmaker aams
Codice Bonus bet365: per te bonus benvenuto fino a 100. Scommetti sullo sport 2018! - si applicano T&C (gioca responsabile 18+) - registrati qui!
Vendita lastre plexiglass su misura
Sito di vendita online lastre di plexiglass tagliate su misura al laser. Il configuratore di prodotto permette di scegliere forme e misure diverse per ciascuna lastra. Le spedizioni avvengono tramite corriere espresso in tutta Italia, sia verso aziende sia verso clienti privati. Il sito ha una sezione informativa composta da articoli inerenti la lavorazione di materie plastiche.
News calciomercato
Scopri le ultime news di calciomercato in tempo reale sulla tua squadra di Serie A e non solo. Notizie 24 ore su 24 su calcio estero.
Hotel Ischia - Scegli Ischiaprenota.com
Cerchi un hotel Ischia? Su Ischiaprenota.com tantissime offerte hotel e lastminute Ischia a prezzi imbattibili. Hotel 3,4 e 5 stelle a partire da 20 a notte. Trattamento All-Inclusive, Pensione completa, Mezza Pensione e solo pernottamento. Nessun anticipo, paghi direttamente in hotel. Assistenza con personale Ischitano.

Inserisci il tuo sito nella directory...

Manuale PHP


Exceptions

Table of Contents

PHP 5 has an exception model similar to that of other programming languages. 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. Multiple catch blocks can be used to catch different classes of exceptions. Normal execution (when no exception is thrown within the try block, or when a catch matching the thrown exception's class is not present) will continue after that last catch block defined in sequence. Exceptions can be thrown (or re-thrown) within a catch block.

When an exception is thrown, code following the statement will not be executed, and PHP will attempt to find the first matching catch block. If an exception is not caught, a PHP Fatal Error will be issued with an "Uncaught Exception ..." message, unless a handler has been defined with set_exception_handler().

The thrown object must be an instance of the Exception class or a subclass of Exception. Trying to throw an object that is not will result in a PHP Fatal Error.

Note:

Internal PHP functions mainly use Error reporting, only modern Object oriented extensions use exceptions. However, errors can be simply translated to exceptions with ErrorException.

Tip

The Standard PHP Library (SPL) provides a good number of built-in exceptions.

Example #1 Throwing an Exception

<?php
function inverse($x) {
    if (!
$x) {
        throw new 
Exception('Division by zero.');
    }
    else return 
1/$x;
}

try {
    echo 
inverse(5) . "n";
    echo 
inverse(0) . "n";
} catch (
Exception $e) {
    echo 
'Caught exception: ',  $e->getMessage(), "n";
}

// Continue execution
echo 'Hello World';
?>

The above example will output:

0.2
Caught exception: Division by zero.
Hello World

Example #2 Nested Exception

<?php

class MyException extends Exception { }

class 
Test {
    public function 
testing() {
        try {
            try {
                throw new 
MyException('foo!');
            } catch (
MyException $e) {
                
/* rethrow it */
                
throw $e;
            }
        } catch (
Exception $e) {
            
var_dump($e->getMessage());
        }
    }
}

$foo = new Test;
$foo->testing();

?>

The above example will output:

string(4) "foo!"