I want to be able to "make" browser display errors, like forbidden, 503 etc...
Is there some kind of sandbox where I could do this?
I need the errors to be rendered in google chrome, then take a screen capture of browser window.
Something like image under it, but force the browser to display something like this, maybe in Chrome dev tools could be done?
CodePudding user response:
You can do this with try-catch condition and set_exception_handler function like this:
<?php
class MyCustomException extends Exception { }
function exception_handler($exception) {
echo "Uncaught exception: " , $exception->getMessage(), "\n";
}
set_exception_handler('exception_handler');
try {
throw new Exception('Uncaught Exception');
} catch (MyCustomException $e) {
echo "Your custom exception caught ";
echo $e->getMessage();
} finally {
echo "I'm always here";
}
print "Not executed";
For more information you may visit site https://netgen.io/blog/modern-error-handling-in-php
CodePudding user response:
You can simply use try & catch, you can check function inside try and throw error to catch. For example i need to run mysql if is there any error report it..
So here is function for it
try{
if(!mysqli_query($conn,$query)){
throw new Exception(you can put query error)
}
}catch(Exception $e){
print_r($e)
}
the $e inside catch will give you erro