·  PHP – Syntax – OOP – Exceptions – Catch

 

- Info:

  - Exception class supports multiple functions which allow you to get additioanl info about Exception.

 

- Example:

  - Creat PHP Console Application Test.php.

 

    Test.php

    <?php

      

      try {

        throw new Exception("UPS", 5); //Two parameters. Second is accessable with $e->getCode()

      }

      catch (Exception $e) {

        echo "Caught exception: \n";

        echo "Message = " . $e->getMessage() . "\n"; //First  optioanl parameter.

        echo "Code    = " . $e->getCode()    . "\n"; //Second optional parameter.

        echo "Line    = " . $e->getLine()    . "\n"; //6

        echo "File    = " . $e->getFile()    . "\n"; //D:\Installed\...\Test.php

        echo "File    = " . $e->getTraceAsString();  //Returns getTrace() as String.                 

        print_r($e->getTrace());                   

      }

      

    ?>