Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Non-fatal error handling with Mouse types?

by wanna_code_perl (Friar)
on Oct 02, 2019 at 11:30 UTC ( #11106949=note: print w/replies, xml ) Need Help??


in reply to Re: Non-fatal error handling with Mouse types?
in thread Non-fatal error handling with Mouse types?

$obj->error_mode() would in fact be called externally, and there are several such similar setter subs. The trivially alliterative answer to your second question is "yes". I love exceptions, too, but they were not the best choice for this project.

Replies are listed 'Best First'.
Re^3: Non-fatal error handling with Mouse types?
by 1nickt (Abbot) on Oct 02, 2019 at 12:11 UTC

    If when a consumer of your class calls a function with a bad value, you don't want to raise an exception, then I don't understand why you are using type constraints.


    The way forward always starts with a minimal test.

      I want to constrain some inputs (A). And I don't have an exception-based error model (B). I believe the misunderstanding is that I have A ∧ ¬B, but you've just argued A → B. I already have a normal OO version of the same class that constrains said input types and works just fine without exceptions, so clearly ¬(A → B). I'm really just here for some help with Mouse.

        It also sounds off to me. Fatals—or undef with warnings, or returning an objectified error—are the proper action for a broken object. Returning a broken/useless object with an “error state” included seems like a worst practice to me.

        Sorry, I don't know what that notation means. I see from your previous threads that you know what an XY problem is so I imagine you are sure that using type constraints where the type is not actually constrained is not barking up the wrong tree. It is however contrary to the standard use of constraints, hence the solutions you have found acceptable are limited to further abusing the tools you have.

        Maybe you wish to conform the provided values to a range of acceptable ones instead? Perhaps you could make use of coercions in conjunction with your constraints in that case.


        The way forward always starts with a minimal test.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11106949]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2021-01-16 11:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?