14.
Probando Excepciones Excepcionales
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
4 Comments
Since we're using PHP ^8.0, I think that also correct way to use null-coalesce operator throwing an exception:
In that case, we don't need to declare extra variables, but should think about line length and good readability.
Also, in case within two issues for same Dinosaur with different labels we can face exception, when shouldn't (if latest label is Healthy, but previous is unknown and not closed for some reasons).
In addition, in test class it's possible to instantiate an exception, and use
expectExceptionObject, which can be useful in some cases (f.i., within data providers).Hi yaroslavche!
That's a cool idea to use the null-coalesce to throw an exception - like it!
I'm actually not familiar with
expectExceptionObject()- and I could find almost no info on it! It looks undocumented, though a comment on StackOverflow says that it works as of PHPUnit 9.5. So, super interesting!Cheers!
expectExceptionObjectis just a sugar forexpectException,expectExpceptionMessageandexpectExceptionCode.the same as
Beautiful - I like that a lot!
"Houston: no signs of life"
Start the conversation!