MemoryRefresh!

Features / Exceptions   Exceptions



Questions Answers 0%

Pages   0 from 91
Questions   0 from 142

Reset


An exception that is thrown in try{} block is passed on to catch{} block.
<?php $error = true; try { if ($error) { throw new Exception ("This is my error"); } } catch (Exception $e) { echo $e->getMessage(); // --- Look Here --- // // output: This is my error } Exception class can be extended, to use different nested try/catch blocks.
<?php class myException extends Exception { } try { // ... } catch (myException $e) { // --- Look Here --- // echo $e->getMessage(); } } catch (Exception $e) { echo $e->getMessage(); } PHP allows to define a catch-all function that is automatically called.
<?php function handleUncaughtExcetion($e) { echo $e->getMessage(); } set_exception_handler("handleUncaughtExcetion"); throw new Exception ("My error!"); // output: My error! echo "This is never displayed"; // Without exception handler, will have: // --- Look Here --- // // Fatal error: Uncaught exception 'Exception' with message 'My error!'
1) How do you generate an exception?





2) To avoid default Fatal error message, which function do you use?









An exception that is thrown in try{} block is passed on to catch{} block.
<?php $error = true; try { if ($error) { throw new Exception ("This is my error"); } } catch (Exception $e) { echo $e->getMessage(); // --- Look Here --- // // output: This is my error } Exception class can be extended, to use different nested try/catch blocks.
<?php class myException extends Exception { } try { // ... } catch (myException $e) { // --- Look Here --- // echo $e->getMessage(); } } catch (Exception $e) { echo $e->getMessage(); } PHP allows to define a catch-all function that is automatically called.
<?php function handleUncaughtExcetion($e) { echo $e->getMessage(); } set_exception_handler("handleUncaughtExcetion"); throw new Exception ("My error!"); // output: My error! echo "This is never displayed"; // Without exception handler, will have: // --- Look Here --- // // Fatal error: Uncaught exception 'Exception' with message 'My error!'

References









Programming

Php
   
Regex
   
MySQL
   
Css
   
jQuery
   
Git
   


References