Skip to content

Commit

Permalink
improve errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nrenvoise-ubitransport committed Jun 25, 2021
1 parent 0d7adc9 commit c236549
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
23 changes: 23 additions & 0 deletions error_exception/error_reporting/error_reporting.php
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 error_exception/errors_vs_exceptions/errors_vs_exceptions.php
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);

0 comments on commit c236549

Please sign in to comment.