Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
C0D4681454yOutside of rolling your own error handler and throwing exceptions that way 🤔
PHP7 has a lot of throwable errors you can try/catch with but as for warnings, can't say I've set them up as errors / exceptions before. Not all warnings are erroneous. -
@C0D4
I already have my own global error handler.
But it would be nice to be able to "catch" notices and warnings in the calling code. -
C0D4681454y@Oktokolo off the top of my head, using Trigger_error() with E_Warning / E_Notice and having your own error handler to output debug_backtrace() so you have some useful output could work.
-
@C0D4
Thanks for the nudge.
Out of curiosity i tried throwing an exception inside the error handler and it indeed just worked. Even the trace is correct.
Can't believe i didn't try that back then when i wrote the global error handler... -
Just a reminder to be careful...
If you have an exception handler - it must not generate an exception or error.
Relevant as you can trigger a fun recursion when the error handle generates an exception, the exception handler kicks in, throws an error, the error handler kicks in.... You get the idea.
Related Rants
For the PHP pros: Is there a way of turning notices and warnings into exceptions thrown in the scope of occurence without hacking the interpreter?
The answer most likely is "No!" - but if there is another way i certainly would like to know it...
question
php