I recently read "Object Oriented Exception Handling in Perl" Perl.com article. Is there any point to use exceptions in Perl?
I should note that the article you referenced is old, and that you should now use Exception::Class instead of Error.pm, which is quirky and tends to break (it's what I call "black magick"). I should note that I am now the Error.pm maintainer, but I no longer recommend it or make use of it for my own code.
"is there any point to use exceptions in Perl?"
Yes, I highly recommend reading the "Error Handling" chapter in Perl Best Practices by Damian Conway.
It certainly opened my eyes ;-)
Absolutely. If you throw a simple 'die', you really don't have any more information that the computer can handle. For example, I have a test framework which uses Test::Most and that module can allow you to die on test failures. However, my framework needed to know if I was dying because a test failed or because the code died. Thus, I threw a Test::Most::Exception and my framework can check the exception type and take appropriate action.
Exceptions are your friend :)
In any programming language, exceptions can allow you to deal with different types of errors in different ways. This can be really useful for keeping track of fine-grained errors in testing and intelligently dealing the recoverable errors within your program. It's not worthwhile for every throwaway program you write, but for things you spend a lot of time developing it can be worth the effort.
© 2022 - 2024 — McMap. All rights reserved.