On error resume next

Hi,

In the following code, how can I implement the VB "On Error Resume Next"
in ruby?

def error
raise "ERROR_DELIBERATE"
print "I’m back"
end
begin
error
print "Finishing…"
rescue
???
end

Can I let my program execute either of the 2 print? If I use retry, it
will re-run error, and lock the program.

Thanks
Shannon

Put the code you want to be executed in ensure:

begin
error
rescue
ensure
print “Finishing…”
end

You will get “Finishing…” printed out despite any exception, rescued or
not.

Gennady.

···

----- Original Message -----
From: “Shannon Fang” xrfang@hotmail.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, December 05, 2002 2:21 PM
Subject: on error resume next

Hi,

In the following code, how can I implement the VB “On Error Resume Next”
in ruby?

def error
raise “ERROR_DELIBERATE”
print “I’m back”
end
begin
error
print “Finishing…”
rescue
???
end

Can I let my program execute either of the 2 print? If I use retry, it
will re-run error, and lock the program.

Thanks
Shannon

Hi,

In the following code, how can I implement the VB “On Error Resume Next”
in ruby?

I’m not sure why you want a such vice, but what about this?

def raise(*args)
super unless $ignore_error
end

def on_error_resume_next
ignore_error = $ignore_error
$ignore_error = true
yield
ensure
$ignore_error = ignore_error
end

def error
raise “ERROR_DELIBERATE”
puts “I’m back”
end

on_error_resume_next do
error
puts “Finishing…”
end

···

At Fri, 6 Dec 2002 07:21:29 +0900, Shannon Fang wrote:


Nobu Nakada

Hi,

Not what I want :frowning: I want “On Error Resume Next”… If that is
available in ruby.

Shannon

···

On Fri, 6 Dec 2002 07:48:42 +0900 “Gennady F. Bystritsky” gfb@tonesoft.com wrote:

Put the code you want to be executed in ensure:

begin
error
rescue
ensure
print “Finishing…”
end

You will get “Finishing…” printed out despite any exception, rescued or
not.

Gennady.

----- Original Message -----
From: “Shannon Fang” xrfang@hotmail.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, December 05, 2002 2:21 PM
Subject: on error resume next

Hi,

In the following code, how can I implement the VB “On Error Resume Next”
in ruby?

def error
raise “ERROR_DELIBERATE”
print “I’m back”
end
begin
error
print “Finishing…”
rescue
???
end

Can I let my program execute either of the 2 print? If I use retry, it
will re-run error, and lock the program.

Thanks
Shannon

On Fri, 6 Dec 2002 19:52:16 +0900
In article 200212061052.gB6AqE202961@sharui.nakada.kanuma.tochigi.jp
[Re: on error resume next]

In the following code, how can I implement the VB “On Error Resume Next”
in ruby?

I’m not sure why you want a such vice, but what about this?

No. :slight_smile:

“On Error Resume Next” depends its static context.

—^ test.vbs
Sub Test
WScript.Echo “before raise”
Err.Raise 1
WScript.Echo “after raise”
End Sub

On Error Resume Next
WScript.Echo “before test”
Test
WScript.Echo “after test”
—$

D:> cscript test.vbs
before test
before raise
after test

Oh, no! “after raise” is not printed!
To print, we have to insert “On Error Resume Next” line after
“Sub Test”.

Ruby cannot simulate this behavior.

–[ Tietew ]-------------------------------------------------------
Mail: tietew@tietew.net / tietew@raug.net
Web : http://www.tietew.net/ (Tietew Windows Lab.)
PGP fingerprint: 26CB 71BB B595 09C4 0153 81C4 773C 963A D51B 8CAA

···

nobu.nokada@softhome.net wrote:

That’s so ugly it could be a modern art masterpiece! Please, can we have some
more VB? Please? :slight_smile:

Gavin

···

From: nobu.nokada@softhome.net

I’m not sure why you want a such vice, but what about this?

def raise(*args)
super unless $ignore_error
end

def on_error_resume_next
ignore_error = $ignore_error
$ignore_error = true
yield
ensure
$ignore_error = ignore_error
end

def error
raise “ERROR_DELIBERATE”
puts “I’m back”
end

on_error_resume_next do
error
puts “Finishing…”
end

Why would you want that? If you gave us some real-life code, perhaps we
might suggest a structure that works in Ruby.

Cheers

Dave

···

On Thu, 2002-12-05 at 17:03, Shannon Fang wrote:

Not what I want :frowning: I want “On Error Resume Next”… If that is
available in ruby.

Not what I want :frowning: I want “On Error Resume Next”… If that is
available in ruby.

#!/usr/local/bin/ruby

def error
callcc do |$on_error_resume_next|
raise “ERROR_DELIBERATE”
end
puts “I’m back”
end

begin
error
puts “Finishing…”
rescue
$on_error_resume_next.call
end

I’m back
Finishing…

-a

···

On Fri, 6 Dec 2002, Shannon Fang wrote:

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

Ruby cannot simulate this behavior.

You are trying to force ruby to become what you know, instead of learning
ruby’s different methods of doing the same thing.

The ‘def raise(*args)…’ solution given is pretty much what you want,
and if you want it clobal then $ignore_errors = 1. That it’s syntax is
different than VBs is a nonissue… If you want VB, stick with VB, don’t
turn ruby into VB.

Of course, it could help if you explained more what ‘On Error Resume Next’
does … does it make the script completely ignore all raised errors? does
it affect all errors? system errors? errors raised by you?

···

Greg Millam
walker at deafcode.com

Not what I want :frowning: I want “On Error Resume Next”… If that is
available in ruby.

#!/usr/local/bin/ruby

def error
callcc do |$on_error_resume_next|
raise “ERROR_DELIBERATE”
end
puts “I’m back”
end

begin
error
puts “Finishing…”
rescue
$on_error_resume_next.call
end

I’m back
Finishing…

NOOOOOO!!! My head hurts!!!

Gavin

···

From: “ahoward” ahoward@fsl.noaa.gov

On Fri, 6 Dec 2002, Shannon Fang wrote:

Hi

I'm sorry I don't understand why $on_error...? Is it mean Global var?
again, ... symbol...

I tried to do the following: (peudo-code)

def test
       begin
  conn=adodb.connection
  conn.open ...
  if conn!=nil then
    #add data to db
  else
    #add data to file
  end
       rescue DBError
  conn=nil
  resume next
       end
end

···

On Thu, 5 Dec 2002 23:50:12 +0000 (GMT) ahoward <ahoward@fsl.noaa.gov> wrote:

On Fri, 6 Dec 2002, Shannon Fang wrote:

> Not what I want :frowning: I want "On Error Resume Next"... If that is
> available in ruby.

  #!/usr/local/bin/ruby

  def error
    callcc do |$on_error_resume_next|
      raise "ERROR_DELIBERATE"
    end
    puts "I'm back"
  end

  begin
    error
    puts "Finishing..."
  rescue
    $on_error_resume_next.call
  end

>> I'm back
>> Finishing...

-a

--

====================================
> Ara Howard
> NOAA Forecast Systems Laboratory
> Information and Technology Services
> Data Systems Group
> R/FST 325 Broadway
> Boulder, CO 80305-3328
> Email: ahoward@fsl.noaa.gov
> Phone: 303-497-7238
> Fax: 303-497-7259

Ruby cannot simulate this behavior.

You are trying to force ruby to become what you know, instead of learning
ruby’s different methods of doing the same thing.

The ‘def raise(*args)…’ solution given is pretty much what you want,
and if you want it clobal then $ignore_errors = 1. That it’s syntax is
different than VBs is a nonissue… If you want VB, stick with VB, don’t
turn ruby into VB.

Couldn’t agree more.

Of course, it could help if you explained more what ‘On Error Resume Next’
does … does it make the script completely ignore all raised errors? does
it affect all errors? system errors? errors raised by you?

I think more to the point is that the OP should present the problem he’s trying
to solve and seek advice on how it can be done in Ruby. It’s a design thing
more than a Ruby thing, as several languages now have exception handling, and
VB has graceless hacks.

This has been done, however (i.e. a Ruby rationalisation). Whether it has been
done to the OP’s liking is another matter.

Gavin

···

From: “Greg Millam” walker@deafcode.com

lol.

i couldn’t actually think of a shorter way to do it! besides, that’s what one
gets for trying to squeeze ruby into a vb box - a headache :wink:

-a

···

On Fri, 6 Dec 2002, Gavin Sinclair wrote:

NOOOOOO!!! My head hurts!!!

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

I'm sorry I don't understand why $on_error...? Is it mean Global var?
again, ... symbol...

yup.

I tried to do the following: (peudo-code)

def test
       begin
  conn=adodb.connection
  conn.open ...
  if conn!=nil then
    #add data to db
  else
    #add data to file
  end
       rescue DBError
  conn=nil
  resume next
       end
end

i don't quite understand this... the next WHAT? where is the implied loop
supposed to be?

-a

···

On Fri, 6 Dec 2002, Shannon Fang wrote:

--

====================================
> Ara Howard
> NOAA Forecast Systems Laboratory
> Information and Technology Services
> Data Systems Group
> R/FST 325 Broadway
> Boulder, CO 80305-3328
> Email: ahoward@fsl.noaa.gov
> Phone: 303-497-7238
> Fax: 303-497-7259

Hi

I’m sorry I don’t understand why $on_error…? Is it mean Global var?
again, … symbol…

RTFM :wink:

···

On Thursday, Dec 5, 2002, at 18:10 US/Pacific, Shannon Fang wrote:

I tried to do the following: (peudo-code)

def test
begin
conn=adodb.connection
conn.open …
if conn!=nil then
#add data to db
else
#add data to file
end
rescue DBError
conn=nil
resume next
end
end

On Thu, 5 Dec 2002 23:50:12 +0000 (GMT) > ahoward ahoward@fsl.noaa.gov wrote:

On Fri, 6 Dec 2002, Shannon Fang wrote:

Not what I want :frowning: I want “On Error Resume Next”… If that is
available in ruby.

#!/usr/local/bin/ruby

def error
callcc do |$on_error_resume_next|
raise “ERROR_DELIBERATE”
end
puts “I’m back”
end

begin
error
puts “Finishing…”
rescue
$on_error_resume_next.call
end

I’m back
Finishing…

-a

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

If I remember from my VB days, the Resume Next resumes at the
next line/statement.

Ruby would have an issue implementing this since it is not line based.
To emulate this in ruby, one would have to use goto’s or nested
resumes, which are not possible.

···

On Friday, 6 December 2002 at 21:00:28 +0900, Gavin Sinclair wrote:

From: “Greg Millam” walker@deafcode.com

Ruby cannot simulate this behavior.

You are trying to force ruby to become what you know, instead of learning
ruby’s different methods of doing the same thing.

The ‘def raise(*args)…’ solution given is pretty much what you want,
and if you want it clobal then $ignore_errors = 1. That it’s syntax is
different than VBs is a nonissue… If you want VB, stick with VB, don’t
turn ruby into VB.

Couldn’t agree more.

Of course, it could help if you explained more what ‘On Error Resume Next’
does … does it make the script completely ignore all raised errors? does
it affect all errors? system errors? errors raised by you?


Jim Freeze

Documentation is like sex: when it is good, it is very, very good; and
when it is bad, it is better than nothing.
– Dick Brandon

I need the logic, not to squeeze into vb… pls see my sample code, I
don’t think the solution is as neat as vb. For example:

def error
callcc do |$on_error_resume_next|
puts “Before Error…”
raise “ERROR_DELIBERATE”
puts “after error”
end
puts “I’m back”
end

begin
error
puts “Finishing…”
rescue
$on_error_resume_next.call
end

The “after error” will not be printed. If I create a callcc block for
every possible error, that will be a headache

What do you think?

S

···

On Fri, 6 Dec 2002 10:37:00 +0900 ahoward ahoward@fsl.noaa.gov wrote:

On Fri, 6 Dec 2002, Gavin Sinclair wrote:

NOOOOOO!!! My head hurts!!!

lol.

i couldn’t actually think of a shorter way to do it! besides, that’s what one
gets for trying to squeeze ruby into a vb box - a headache :wink:

-a

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

Hi,

···

On Fri, 6 Dec 2002 02:26:40 +0000 (GMT) ahoward <ahoward@fsl.noaa.gov> wrote:

> I tried to do the following: (peudo-code)
>
> def test
> begin
> conn=adodb.connection
> conn.open ...
> if conn!=nil then
> #add data to db
> else
> #add data to file
> end
> rescue DBError
> conn=nil
> resume next
> end
> end

i don't quite understand this... the next WHAT? where is the implied loop
supposed to be?

The benefit of resume next is that it will catch all errors. Here, I
expect error to happen on the conn.open statement., so if error happen,
set conn=nil.

shannon

Hi,

···

At Fri, 6 Dec 2002 23:45:07 +0900, Jim Freeze wrote:

If I remember from my VB days, the Resume Next resumes at the
next line/statement.

Ruby would have an issue implementing this since it is not line based.
To emulate this in ruby, one would have to use goto’s or nested
resumes, which are not possible.

set_trace_func could be used, but I’m not sure about it nor
want to try it. :slight_smile:


Nobu Nakada

“Jim Freeze” jim@freeze.org wrote in message
news:20021206095202.A67520@freeze.org

···

On Friday, 6 December 2002 at 21:00:28 +0900, Gavin Sinclair wrote:

From: “Greg Millam” walker@deafcode.com

If I remember from my VB days, the Resume Next resumes at the
next line/statement.

Ruby would have an issue implementing this since it is not line based.
To emulate this in ruby, one would have to use goto’s or nested
resumes, which are not possible.

Would it help to think of it as ResumeNextStatement instead of
ResumeNextLine?

Mikkel