4 assert('Exception', '15.2.22') do
5 assert_equal Class, Exception.class
8 assert('Exception.exception', '15.2.22.4.1') do
9 e = Exception.exception('a')
11 assert_equal Exception, e.class
14 assert('Exception#exception', '15.2.22.5.1') do
17 assert_equal e, e.exception
18 assert_equal e, e.exception(e)
19 assert_equal re, re.exception(re)
20 changed_re = re.exception('message has changed')
21 assert_not_equal re, changed_re
22 assert_equal 'message has changed', changed_re.message
25 assert('Exception#message', '15.2.22.5.2') do
26 e = Exception.exception('a')
28 assert_equal 'a', e.message
31 assert('Exception#to_s', '15.2.22.5.3') do
32 e = Exception.exception('a')
34 assert_equal 'a', e.to_s
37 assert('Exception.exception', '15.2.22.4.1') do
38 e = Exception.exception()
41 assert_equal 'a', e.message
44 assert('NameError', '15.2.31') do
45 assert_raise(NameError) do
49 e = NameError.new "msg", "name"
50 assert_equal "msg", e.message
51 assert_equal "name", e.name
54 assert('ScriptError', '15.2.37') do
55 assert_raise(ScriptError) do
60 assert('SyntaxError', '15.2.38') do
61 assert_raise(SyntaxError) do
68 assert('Exception 1') do
77 assert('Exception 2') do
91 assert('Exception 3') do
110 assert('Exception 4') do
118 assert_equal NilClass, a
121 assert('Exception 5') do
136 assert_equal [nil], $ans
139 assert('Exception 6') do
165 assert('Exception 7') do
185 assert('Exception 8') do
196 assert('Exception 9') do
209 assert('Exception 10') do
229 assert('Exception 11') do
242 assert('Exception 12') do
245 raise Exception rescue a = :ng
251 assert('Exception 13') do
255 rescue TypeError, ArgumentError
265 assert('Exception 14') do
266 def (o = Object.new).exception_test14; UnknownConstant end
269 o.__send__(:exception_test14)
277 assert('Exception 15') do
286 assert('Exception 16') do
291 assert_equal "foo", e.message
295 assert('Exception 17') do
297 raise "a" # RuntimeError
310 assert('Exception 18') do
325 assert('Exception 19') do
326 class Class4Exception19
352 assert_equal [true, true], Class4Exception19.new.a
355 assert('Exception#inspect') do
356 assert_equal "Exception", Exception.new.inspect
357 assert_equal "Exception", Exception.new("").inspect
358 assert_equal "error! (Exception)", Exception.new("error!").inspect
361 assert('Exception#backtrace') do
362 assert_nothing_raised do
364 raise "get backtrace"
371 assert('Raise in ensure') do
372 assert_raise(ArgumentError) do
374 raise "" # RuntimeError
381 def backtrace_available?
385 not exception.backtrace.empty?
389 assert('GC in rescue') do
390 skip "backtrace isn't available" unless backtrace_available?
397 line = __LINE__; raise "XXX"
403 assert_equal("#{__FILE__}:#{line}",
404 exception.backtrace.first)
408 assert('Method call in rescue') do
409 skip "backtrace isn't available" unless backtrace_available?
415 line = __LINE__; raise "XXX"
421 assert_equal("#{__FILE__}:#{line}",
422 exception.backtrace.first)