Re: How to capture an div 0 exception

2016-05-18 Thread Richard Hainsworth
On Wednesday, May 18, 2016 11:40 PM, Brandon Allbery wrote: On Wed, May 18, 2016 at 11:29 AM, Brandon Allbery > wrote: On Wed, May 18, 2016 at 11:27 AM, mt1957 mailto:mt1...@gmail.com>> wrote: This has something to do with lazy evaluation. It triggers the

Re: How to capture an div 0 exception

2016-05-18 Thread Brandon Allbery
On Wed, May 18, 2016 at 11:29 AM, Brandon Allbery wrote: > On Wed, May 18, 2016 at 11:27 AM, mt1957 wrote: > >> This has something to do with lazy evaluation. It triggers the >> calculation when it wants to show the value in $r. > > > IIRC it doesn't throw, it returns a Failure (deferred/lazy ex

Re: How to capture an div 0 exception

2016-05-18 Thread Brandon Allbery
On Wed, May 18, 2016 at 11:27 AM, mt1957 wrote: > This has something to do with lazy evaluation. It triggers the calculation > when it wants to show the value in $r. IIRC it doesn't throw, it returns a Failure (deferred/lazy exception that throws when accessed). -- brandon s allbery kf8nh

Re: How to capture an div 0 exception

2016-05-18 Thread mt1957
Hi Richard, This has something to do with lazy evaluation. It triggers the calculation when it wants to show the value in $r. So commenting out the first 'say' will error on the second with the shown response. The CATCH is not at the same scope than the second 'say' statement so there you get

Re: How to capture an div 0 exception

2016-05-18 Thread Richard Hainsworth
Marcel and Moritz, Thank you for the fast response. I have been experimenting with the code you sent, but still do not understand something. To illustrate, here is another snippet: use v6; my $r; for 0..4 -> $s { { $r = 5 / (3 - $s); say "At line $?LINE r is $r"; CATCH {

Re: How to capture an div 0 exception

2016-05-18 Thread Moritz Lenz
On 05/18/2016 01:39 PM, mt1957 wrote: On 18-05-16 13:07, Richard Hainsworth wrote: use v6; my $d = 1; my $e = 2; my $f = 0; #my $r; my $r = 5; CATCH { # when X::AdHoc { when Exception { .Str.say; # $r = 5; .resume } } $r = try { ( $d + $e ) / $f; }; # my $r = try EVAL '

Re: How to capture an div 0 exception

2016-05-18 Thread mt1957
On 18-05-16 13:07, Richard Hainsworth wrote: use v6; my $d = 1; my $e = 2; my $f = 0; #my $r; my $r = 5; CATCH { # when X::AdHoc { when Exception { .Str.say; # $r = 5; .resume } } $r = try { ( $d + $e ) / $f; }; # my $r = try EVAL ' ( 1 + 2 ) /0 '; say "r is $r"; Hi Ric