Is object oriented exception handling in Perl worth it?
Asked Answered
H

4

12

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

Hokusai answered 2/2, 2009 at 13:22 Comment(4)
use expceptions or use object oriented exceptions?Vitrescence
are there normal exception?? or do you mean warn and die?? I'm talking about the OO ones/Hokusai
Thanks for pointing out the article - I learned about oveload module :)Puduns
See also #2165661 and #2440466Unbreathed
T
19

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.

Thomasthomasa answered 2/2, 2009 at 16:32 Comment(2)
I would like to award you a Disciplined badge for recommending others not to use your own module.Extravagate
Link is broken. Should be Exception::Class.Natant
T
13

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

Thermo answered 2/2, 2009 at 15:7 Comment(1)
Link is not working it is giving 404 error!Pebble
A
7

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

Adamite answered 2/2, 2009 at 16:10 Comment(0)
W
3

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.

Wicks answered 2/2, 2009 at 16:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.