in reply to Moose | How to identify subroutine inside an 'around' in case multiple subroutine share the same 'around'?

I suggest that you consider either or both of two approaches:

  1. Define subclasses.   Override the “throw an exception” logic in each one.
  2. Define a single exception-type but allow for a parameter to be sent to the exception handling routine (or reliably retrieved from the object in question), so that a common exception-handling routine can accurately distinguish among the various cases.

“Always keep your eye on the ball.”   Your objective is to be able to easily distinguish between the various objects and error cases; nothing more or less.   “TMTOWTDI!”   Don’t become too wedded to the first approach that pops into your head, then spend too much time trying to implement it.   Always be prepared to step back, to look at the objective afresh, and look for another equally-good way to get there.

  • Comment on Re: Moose | How to identify subroutine inside an 'around' in case multiple subroutine share the same 'around'?

Replies are listed 'Best First'.
Re^2: Moose | How to identify subroutine inside an 'around' in case multiple subroutine share the same 'around'?
by ashish.kvarma (Monk) on Aug 09, 2010 at 13:55 UTC

    I am not very sure about the first point. If you meant sub-classing Exception then that's what I have. Different Exceptions (subclass of Exception) to throw for different subroutines.

    Regarding second point "allow for a parameter to be sent to the exception handling routine"; It has the same problem parameter will depend on subroutine. But you have a good point that it could be retrieved from the object itself (Why I didn't think it :-(. May be I was obsessed with the thought to get something out of Moose itself.).

    Regards,
    Ashish

      In the case of the first point:   the idea here is that, in order to raise an exception, the base-class will call one of its methods.   The descendant classes will then override those methods.   Hence, each descendant class can arrange to throw a particular Exception ... and/or to otherwise distinguish their response from everybody else’s.

      In the case of the second point:   well, it is extremely easy indeed, when faced with the obstacle of a thick iron door, to focus your entire attention upon how to drill through that door ... and, thus, to completely overlook the fact that the door is set into a wooden wall, next to an open window.   (Believe me, it happens to all of us.   That's why Homer Simpson is always whacking himself on the forehead and saying:   “Doh!!”)