|
|
| Perl-Sensitive Sunglasses | |
| PerlMonks |
Re^7: STDERR in Test Resultsby afoken (Chancellor) |
| on Jun 27, 2023 at 21:14 UTC ( [id://11153158]=note: print w/replies, xml ) | Need Help?? |
|
However, I will not call die. I find it frustrating when modules die. WTF? Especially modules where there is a reasonable chance that there may be an error such as when they are dealing with a network or rely on the user to provide input in a particular format such as valid JSON So, what should your module do when being fed with garbage instead of sane input? Pretend nothing evil has happened? Invent other, sane input? Ask for more garbage to be stuffed into your module? What should it do if the network goes down or a required service somewhere on the internet can't be reached? Wait for the heat death of the universe? What should it do if the system runs out of disk space? Gain root privileges and recursively delete all files not used in the last three years? I attempt not to inflict that frustration on others. Get over it. There is nothing to be frustrated about if an exception occurs (i.e. die is called). It is completely normal, it is "just" another way of control flow. The butt-ugly alternative "solution" is to return some kind of error information in-band and check each and every function call result for error information. In other words, C:
Update: Yes, you could implement a kind of exception handling in C using setjmp/sigsetjmp and longjmp/siglongjmp. Be prepared for "interesting" results due to undefined behaviour ... The smart way is to accept that things can go wrong:
(Pseudocode-example stolen from Exception handling.) This can be very useful e.g. if you need to work with a database:
(Ripped right out of the DBI documentation.) Update: Compare with "Exceptions" in Image::Magick: You have to check each and every return value, and you need to do that in at least three different ways, depending on what the function is expected to return. There is NO exception handing in Image::Magick. The main point is that if you accidentally forget to check for errors, your programm will die. It won't chew on garbage that happens to linger around somewhere in memory and it won't produce any more garbage. It will just stop and exit with an error message. In C, omitting error checks will cause a lot of "interesting" results instead. Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||||