# New Ticket Created by Jonas Kramer # Please include the string: [perl #129956] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org/Ticket/Display.html?id=129956 >
For most (all I've tested) types the method .Int works pretty much the same and as I'd expect: it either returns an Int or, if not possible because the invocant can't be converted to Int in a useful way or the invocant is not defined, it throws an exception. However Cool and classes that inherit from it and don't override the .Int method (namely Nil) behave differently in a potential harmful way: instead of throwing an exception, .Int here prints an error and returns 0. The problem with this is a) I can't check if a problem occured with try/CATCH, b) I can't check if the conversion succeeded by checking the return value, since 0 is a valid and defined Int and c) it's very inconsistent with other types and makes me have to write extra checks prior to calling .Int. Random example: given try prompt('int: ').Int { when Int { say "you just entered the integer $_" } default { say "that was totally not an integer" } } This would normally allow me to prompt for a number and easily check if the input indeed was a valid number. The only problem is Nil (returned by prompt in case of EOF), which becomes 0, which is rather unexpected behavior in my opinion. Also finally, since .Int on Nil/Cool:U is already printing an error, I think it's obvious that calling .Int on them indeed *is* an error, so instead of printing that but continuing normally by returning 0 it should actually behave like there was an error, i.e. throw and exception so the programmer can deal with it using regular control flow (try/CATCH) and not make guesses about whether the invocant contained some value that was successfully converted to 0 or if the conversion failed.