[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Trapping error not caught by rescue Exception -- How to?

RichardOnRails

12/17/2006 2:46:00 AM

Hi,

The fourth data line in the program below hangs rather than submitting
to the rescue clause. How can I trap that kind of error?

I'm running WinXP-Pro/SP2, Ruby 1.8.2-15, Rails 1.1.6, MySQL
5.0.15-nt, SciTE 1.59

TIA,
Richard

=== code start ===
begin
DATA.each do |line|
var, expr, excess = line.chomp.split(/=/, 3)
var.strip!; expr.strip!
puts "expr=" + expr + ", expr.class=" +expr.class.to_s
puts "eval(expr)=" + eval(expr).to_s
end
rescue Exception => eMsg
puts "ERROR: " + eMsg
retry
end

__END__
a = 5**2 =# 25
b =date =# undefined local variable or method `date' for
main:Object
c = y =# undefined local variable or method `y' for main:Object
c =`date` =# (ruby hangs; Ctrl-C kills it)
=== code end ===

5 Answers

Daniel Finnie

12/17/2006 3:05:00 AM

0

Ruby doesn't hang when I run that code.

This is the output:
daniel@daniel-desktop:~$ ruby /tmp/tmp.rb
expr=5**2, expr.class=String
eval(expr)=25
expr=date, expr.class=String
ERROR: undefined local variable or method `date' for main:Object
ERROR: undefined method `strip!' for nil:NilClass
expr=y, expr.class=String
ERROR: undefined local variable or method `y' for main:Object
expr=`date`, expr.class=String
eval(expr)=Sat Dec 16 22:01:37 EST 2006

Richard wrote:
> Hi,
>
> The fourth data line in the program below hangs rather than submitting
> to the rescue clause. How can I trap that kind of error?
>
> I'm running WinXP-Pro/SP2, Ruby 1.8.2-15, Rails 1.1.6, MySQL
> 5.0.15-nt, SciTE 1.59
>
> TIA,
> Richard
>
> === code start ===
> begin
> DATA.each do |line|
> var, expr, excess = line.chomp.split(/=/, 3)
> var.strip!; expr.strip!
> puts "expr=" + expr + ", expr.class=" +expr.class.to_s
> puts "eval(expr)=" + eval(expr).to_s
> end
> rescue Exception => eMsg
> puts "ERROR: " + eMsg
> retry
> end
>
> __END__
> a = 5**2 =# 25
> b =date =# undefined local variable or method `date' for
> main:Object
> c = y =# undefined local variable or method `y' for main:Object
> c =`date` =# (ruby hangs; Ctrl-C kills it)
> === code end ===
>
>
>

RichardOnRails

12/17/2006 4:02:00 AM

0

Hi Daniel,

Thanks for your results. I suspect you were running on Uni*. I was
running in SciTE over WindowsXP.

When I ran the program in a Command window, I saw what the problem is:
in Windows, the date command waits for keyboard input specifying a new
system date. That wasn't apparent when I was running under SciTE.

So, all's well in my Ruby sandbox.

Regards,
Richard


Daniel Finnie wrote:
> Ruby doesn't hang when I run that code.
>
> This is the output:
> daniel@daniel-desktop:~$ ruby /tmp/tmp.rb
> expr=5**2, expr.class=String
> eval(expr)=25
> expr=date, expr.class=String
> ERROR: undefined local variable or method `date' for main:Object
> ERROR: undefined method `strip!' for nil:NilClass
> expr=y, expr.class=String
> ERROR: undefined local variable or method `y' for main:Object
> expr=`date`, expr.class=String
> eval(expr)=Sat Dec 16 22:01:37 EST 2006
>
> Richard wrote:
> > Hi,
> >
> > The fourth data line in the program below hangs rather than submitting
> > to the rescue clause. How can I trap that kind of error?
> >
> > I'm running WinXP-Pro/SP2, Ruby 1.8.2-15, Rails 1.1.6, MySQL
> > 5.0.15-nt, SciTE 1.59
> >
> > TIA,
> > Richard
> >
> > === code start ===
> > begin
> > DATA.each do |line|
> > var, expr, excess = line.chomp.split(/=/, 3)
> > var.strip!; expr.strip!
> > puts "expr=" + expr + ", expr.class=" +expr.class.to_s
> > puts "eval(expr)=" + eval(expr).to_s
> > end
> > rescue Exception => eMsg
> > puts "ERROR: " + eMsg
> > retry
> > end
> >
> > __END__
> > a = 5**2 =# 25
> > b =date =# undefined local variable or method `date' for
> > main:Object
> > c = y =# undefined local variable or method `y' for main:Object
> > c =`date` =# (ruby hangs; Ctrl-C kills it)
> > === code end ===
> >
> >
> >

GLOBALIST

4/14/2013 5:11:00 PM

0

Let's call it an atheist after life

Dakota

4/15/2013 8:02:00 PM

0

On 4/15/2013 1:41 PM, Brian E. Clark wrote:
> In article <kked1f$mbv$1@dont-email.me>, sbalneav@alt-
> atheism.org says...
>
>> Subject: Re: Sage Advice About Being Buried In A Coffin - From The Wise One
>
> In light of modern burial practices, what we really need is
>
> Sage Advice About Being Hooked up to
> an Embalming Apparatus.
>
'Sage Advice about Surviving Cremation' might also be a good topic in
today's society.

*^&%$$#*%!

4/16/2013 12:26:00 AM

0

On Sun, 14 Apr 2013 14:04:31 +0000, sbalneav wrote:

> In alt.atheism Brother Bruno <bruno@nobody.com> wrote:
>> First, DON?T PANIC!
>
> That'll be rather hard to do with all your blood replaced with formaldehyde
> embalming mixture.

It didn't stop Dr. Phibes, now, did it?

--
MarkA

If you can read this, you can stop reading now.