Rescue

Hello

begin [1,2,3].each {|x| p x, x/0 }; rescue; end
# this ends after the first error, I want it to continue till the end, ignoring all errors inside
What to change, what is wrong?

thanks
Opti

The placement of "rescue". :wink:

robert

···

On Tue, Mar 7, 2017 at 7:29 PM, Die Optimisten <inform@die-optimisten.net> wrote:

begin [1,2,3].each {|x| p x, x/0 }; rescue; end
# this ends after the first error, I want it to continue till the end,
ignoring all errors inside
What to change, what is wrong?

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

try this

[1,2,3].each {|x| begin p x, x/0; rescue; end; }

···

On 7 March 2017 at 19:29, Robert Klemme <shortcutter@googlemail.com> wrote:

On Tue, Mar 7, 2017 at 7:29 PM, Die Optimisten > <inform@die-optimisten.net> wrote:

> begin [1,2,3].each {|x| p x, x/0 }; rescue; end
> # this ends after the first error, I want it to continue till the end,
> ignoring all errors inside
> What to change, what is wrong?

The placement of "rescue". :wink:

robert

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

If I understood what you are trying to get.

[1,2,3].each {|x| p x, begin x/0; rescue; end; }

will puts the original value and nil (because that is what rescue returns).

For example if you want to put 0 when a division is not possible (raises
exception) try this:

[1,2,3].each {|x| p x, begin x/0; rescue; 0 end; }

Hope this helps.

···

On 7 March 2017 at 19:31, Hugo Leonel Angelo <hugoangelo@gmail.com> wrote:

try this

[1,2,3].each {|x| begin p x, x/0; rescue; end; }

On 7 March 2017 at 19:29, Robert Klemme <shortcutter@googlemail.com> > wrote:

On Tue, Mar 7, 2017 at 7:29 PM, Die Optimisten >> <inform@die-optimisten.net> wrote:

> begin [1,2,3].each {|x| p x, x/0 }; rescue; end
> # this ends after the first error, I want it to continue till the end,
> ignoring all errors inside
> What to change, what is wrong?

The placement of "rescue". :wink:

robert

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

_You_ should have tried...

Cheers

robert

···

On Tue, Mar 7, 2017 at 8:31 PM, Hugo Leonel Angelo <hugoangelo@gmail.com> wrote:

try this

[1,2,3].each {|x| begin p x, x/0; rescue; end; }

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

Hello,

My question is "ignoring all errors inside (the block)", which could be seen as blackbox
- Can I achive this by operating only OUTSIDE the block?

ok - not so well described before...
thanks
Opti

···

On 2017-03-07 20:31, Hugo Leonel Angelo wrote:

try this

[1,2,3].each {|x| begin p x, x/0; rescue; end; }

On 7 March 2017 at 19:29, Robert Klemme <shortcutter@googlemail.com > <mailto:shortcutter@googlemail.com>> wrote:

    On Tue, Mar 7, 2017 at 7:29 PM, Die Optimisten > <inform@die-optimisten.net <mailto:inform@die-optimisten.net>> wrote:

    > begin [1,2,3].each {|x| p x, x/0 }; rescue; end
    > # this ends after the first error, I want it to continue till
    the end,
    > ignoring all errors inside
    > What to change, what is wrong?

    The placement of "rescue". :wink:

    robert

It is still quite foggy though. For example, your initial code will
ignore all errors which occur - it's just that there will ever be only
one because the first exception is caught outside the #each and so
#each is terminated. Every rescue clause has a scope from which it
will catch errors. You need to define what that scope is supposed to
be. There is no mechanism that will just eat all exceptions that occur
- for good reasons. If you think about it this is the only reasonable
way to go about things.

So, if you define what you want to do, you can place proper "begin end
rescue" or expression modifier "rescue" in the places needed.

robert

···

On Tue, Mar 7, 2017 at 10:43 PM, Die Optimisten <inform@die-optimisten.net> wrote:

My question is "ignoring all errors inside (the block)", which could be seen
as blackbox
- Can I achive this by operating only OUTSIDE the block?

ok - not so well described before...

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/