http://doc.perl6.org/routine/warn "To simply print to $*ERR, please use note instead. warn should be reserved for use in threatening situations when you don't quite want to throw an exception."
And for testing, maybe something like this: use Test; my $warning; { warn 'some warning'; CONTROL { when CX::Warn { $warning = .message; } } } is $warning, 'some warning'; On 2016-04-30 09:07:24 IRDT, rnhainsworth wrote: > Hi. Sorry to ask again, but there are two independent questions here. 1) What > is the purpose or best use of 'warn'. 2) How to test code that contains a > 'warn' used as it should be. > 1) I thought that a 'warn' would be used where sometimes the user would want > a fail but not always. I have a module that in normal use I want to continue > even if there is a bad condition which has a default action, but that I can > get to fail if I set an external flag. Maybe I'm wrong. But this is not the > question I originally asked. > 2) whatever may be the purpose of a warn, and I assume there is a good one > since its in core perl6, surely the code that contains it should be tested, > which means triggering the condition and picking up the warning. I can't work > out how to do this. Can't get Test::Output to pick up the message sent to > stderr from warn. > Regards > > > -------- Original message --------From: Larry Wall <la...@wall.org> Date: > 30/04/2016 06:45 (GMT+08:00) To: Brandon Allbery <allber...@gmail.com> Cc: > Timo Paulssen <t...@wakelift.de>, perl6-users <perl6-us...@perl.org> Subject: > Re: testing with a "warn" > On Fri, Apr 29, 2016 at 03:50:21PM -0400, Brandon Allbery wrote: > : On Fri, Apr 29, 2016 at 3:47 PM, Brandon Allbery <allber...@gmail.com> > : wrote: > : > Oh, they are resumable exceptions? Useful but rather high cost I'd think. > : > (Granting that perl6 isn't one of those languages that think exceptions > : > should be normal control flow. But anyone who decides it should be is > : > probably in for a very slow slog.) > > Warnings are implemented like return or next; control exceptions are > more efficient than error exceptions. (This is one of the reasons you > have to catch them with a CONTROL block rather than a CATCH block.) > > : ...also I now know that I should not use warn in many cases where I would > : have otherwise. > > If you need to produce actual warnings in hot code, something's wrong > with your design. (If you just want to print to STDERR, you can use > 'note' instead.) > > Larry