+ 1

How to handle errors and throw exception in php?

18th Aug 2016, 11:15 PM
Bekir Uzun
Bekir Uzun - avatar
2 Réponses
+ 2
using try and catch block. you can genrate your own exception using throw exception. <?php try { $error = 'Always throw this error'; throw new Exception($error); // Code following an exception is not executed. echo 'Never executed'; } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } // Continue execution echo 'Hello World'; ?>
19th Aug 2016, 4:45 AM
Sajir Khan
Sajir Khan - avatar
+ 1
always use var_dump(); on any variable to check for desired output and then check back your code if the output is not the desired one
18th Aug 2016, 11:27 PM
shadow1435