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.
Not what I want 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.
Not what I want 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
====================================
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?
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 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
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.
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
-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
I’m sorry I don’t understand why $on_error…? Is it mean Global var?
again, … symbol…
RTFM
···
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
Not what I want 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:
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 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
-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
====================================
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.
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.
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?