-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d7adc9
commit c236549
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
// Turn off all error reporting | ||
error_reporting(0); | ||
|
||
// Report simple running errors | ||
error_reporting(E_ERROR | E_WARNING | E_PARSE); | ||
|
||
// Reporting E_NOTICE can be good too (to report uninitialized | ||
// variables or catch variable name misspellings ...) | ||
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); | ||
|
||
// Report all errors except E_NOTICE | ||
error_reporting(E_ALL & ~E_NOTICE); | ||
|
||
// Report all PHP errors | ||
error_reporting(E_ALL); | ||
|
||
// Report all PHP errors | ||
error_reporting(-1); | ||
|
||
// Same as error_reporting(E_ALL); | ||
ini_set('error_reporting', E_ALL); |
23 changes: 23 additions & 0 deletions
23
error_exception/errors_vs_exceptions/errors_vs_exceptions.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
function brokenFunction(bool $throwException) { | ||
|
||
if ($throwException) { | ||
throw new RuntimeException('my exception'); | ||
} | ||
|
||
throw new Error('my error'); | ||
} | ||
|
||
function main(bool $throwException) { | ||
try { | ||
brokenFunction($throwException); | ||
} catch (Error $error) { | ||
echo "Error caught!\n"; | ||
} catch (Exception $exception) { | ||
echo "Exception caught!\n"; | ||
} | ||
} | ||
|
||
main(true); | ||
main(false); |