Is object oriented exception handling in Perl worth it?

前端 未结 4 1788
小鲜肉
小鲜肉 2020-12-04 01:32

I recently read \"Object Oriented Exception Handling in Perl\" Perl.com article. Is there any point to use exceptions in Perl?

相关标签:
4条回答
  • 2020-12-04 02:00

    "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 ;-)

    0 讨论(0)
  • 2020-12-04 02:05

    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.

    0 讨论(0)
  • 2020-12-04 02:10

    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.

    0 讨论(0)
  • 2020-12-04 02:17

    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 :)

    0 讨论(0)
提交回复
热议问题