6

I am running analysis on about 10000 lines of numbers, and some of the lines give me errors: "Use of uninitialized value of type Any in numeric context". I am trying to catch this error to see which lines are causing the problem. However, the X::TypeCheck, and other X::* classes don't seem to do effective catching autovivification of Nil or Any. E.g.:

try { say Any + 1; CATCH { default { say "oh-no"; } }; }

still gives me answer of "1" after printing out the warning message and does not say "oh-no" that I want.

What is the proper way to catch these non-fatal autovivification errors? And by the way, is there a nuclear-powered perl6 debugger?

Thank you very much !!!

lisprog

lisprogtor
  • 5,677
  • 11
  • 17
  • 1
    Related mnemonic: For fatal exceptions, P6 goes CRAZY and prepares to CRASH and you must use `CATCH` to CATCH a CRASH and remember to deal properly with the CRAZY program state if you're CRAZY enough to `.resume`. But for *non*-fatal exceptions P6 remains cool and in control and you can stay cool too, doing nothing, or you can use `CONTROL` for control and use `.resume` when you're done without thinking about it. Concretely, `say 1/0` nets you a CRASH you must CATCH and CRAZY you must handle. `say Any + 1` keeps cool and you don't have to do anything unless you want control with `CONTROL`. – raiph Jul 28 '18 at 19:55
  • Thank you very much again, raiph !!! And thanks for the mnemonic :-) – lisprogtor Jul 30 '18 at 07:26

1 Answers1

8

Use quietly and CONTROL instead of try and CATCH:

quietly { say Any + 1; CONTROL { default { say "oh-no" } } }
wamba
  • 3,883
  • 15
  • 21