On error resume next

Move your rescue.

def test
conn = adodb.connection
# Catches ALL possible exceptions from conn.open
conn.open rescue conn = nil
if conn.nil?
# add data to file
else
# add data to DB
end
end

Alternately,

def test
conn = adodb.connection
begin
conn.open
rescue
conn = nil
end
if conn.nil?
# add data to file
else
# add data to DB
end
end

Note that I’ve changed the order of your DB/file operations because
you can’t do a == or != test against nil (nil isn’t equal to
anything except nil).

-austin
– Austin Ziegler, austin@halostatue.ca on 2002.12.05 at 21.35.43

···

On Fri, 6 Dec 2002 11:30:47 +0900, Shannon Fang wrote:

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

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.

No, because it’s still nondeterministic in behaviour. (It’s
something of an implied “goto”.) If the behaviour is really needed,
better to use callcc to explicitly handle it; IMO, it’s probably not
really needed and the perceived need can be eliminated by a little
judicious restructuring of the design and code.

-austin
– Austin Ziegler, austin@halostatue.ca on 2002.12.07 at 14.03.25

···

On Sun, 8 Dec 2002 02:15:43 +0900, MikkelFJ wrote:

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?