Created
May 29, 2015 04:12
-
-
Save anonymous/a5d892c310634ce5c28c to your computer and use it in GitHub Desktop.
PHP try catch error handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<pre> | |
<?php | |
try { | |
echo "Try to do something here.<br />"; | |
throw new Exception("Yikes. Something went funky.<br />", 234); | |
} catch (Exception $e) { | |
//print_r($e); | |
echo $e->getMessage(); | |
} finally { | |
echo "This will always run in our try block.<br />"; | |
} | |
// try { | |
// // connect (create a new MySQLi object) | |
// $mysqli = new MySQLi('localhost', 'root', 'root', 'snippet'); | |
// if (mysqli_connect_error()) { | |
// throw new Exception(mysqli_connect_error()); | |
// } | |
// $sql = "SELECT * FROM search LIMIT 10"; | |
// $result = $mysqli->query($sql); | |
// if (!$result) { | |
// throw new Exception($mysqli->error); | |
// } | |
// while($row = $result->fetch_object()) { | |
// $results[] = $row; | |
// } | |
// } | |
// catch (Exception $e) | |
// { | |
// echo 'We are having issues. Here is how to get help.'; | |
// } | |
// print_r($results); | |
?> | |
</pre> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment