Welcome to the Monastery | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Fellow Monks, Please shine your blessed light on this: I was writing some code using Image::Magick and found myself repeating lines like:
Which I find less than esthetical for several reasons. And even now I::M sometimes printed a warning in stead of giving an error message. I'd rather do:
So I started Image::Magick::Exceptions, borrowing from Simon Cozens' Class::Wrap:
As a proof of concept this works. BUT, things start going wrong when a function is *supposed* to return a string, like the Get/GetAttribute (why all these aliases, by the way?). Reading the documentation again, it says you need to handle methods differently based on what they are supposed to return. Numerical methods should be tested like: Here, evaluating $ret in string context apparently returns something different than evaluating $ret in numerical context. "Void" methods can be tested the same. If the return value is not empty, there's an error. Image operations must be tested like:
And the documentation fails to mention functions that are *supposed* to return string values. I could fix my Image::Magick::Exceptions module, by keeping a list of method names and return types. But where to find these? Even the I::M manual is not clear on what methods return what. Or even fails to mention all methods. And even this doesn't handle the warn()'s that I::M throws every now and then. Finally, and thanks for bearing with my long winded post, the question: Is there a better (non-documented) way to catch errors from I::M? -- In reply to Exception handling for Image::Magick by redlemon
|
|