Fix for JRUBY-2882. Handle error messages related to constructors better
[jruby.git] / bench / shootout / except.ruby
blobd6d61249f4cfa3274fbd4313e1543c48363765f9
1 #!/usr/bin/ruby
2 # -*- mode: ruby -*-
3 # $Id: except.ruby,v 1.1.1.1 2004-05-19 18:09:43 bfulgham Exp $
4 # http://www.bagley.org/~doug/shootout/
6 $HI = 0
7 $LO = 0
8 NUM = Integer(ARGV[0] || 1)
11 class Lo_Exception < Exception
12 def initialize(num)
13 @value = num
14 return self
15 end
16 end
18 class Hi_Exception < Exception
19 def initialize(num)
20 @value = num
21 return self
22 end
23 end
25 def some_function(num)
26 begin
27 hi_function(num)
28 rescue
29 print "We shouldn't get here, exception is: #{$!.type}\n"
30 end
31 end
33 def hi_function(num)
34 begin
35 lo_function(num)
36 rescue Hi_Exception
37 $HI = $HI + 1
38 end
39 end
41 def lo_function(num)
42 begin
43 blowup(num)
44 rescue Lo_Exception
45 $LO = $LO + 1
46 end
47 end
49 def blowup(num)
50 if num % 2 == 0
51 raise Lo_Exception.new(num)
52 else
53 raise Hi_Exception.new(num)
54 end
55 end
58 for iter in 1 .. NUM
59 some_function(iter)
60 end
61 print "Exceptions: HI=", $HI, " / LO=", $LO, "\n"