RuntimeException is defined in IronRuby.Libraries\Builtins\Exceptions.cs. Is MRI really that inconsistent about which type of error is thrown when you try to modify a frozen object? (Not that this would surprise me :(.) If so, it might be cleaner if the call to FreezeObject could record or otherwise influence the type of exception that we expect to throw.
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dave Remy Sent: Sunday, June 29, 2008 3:58 PM To: [email protected] Subject: [Ironruby-core] MutableString.each I am working on one of the specs for string.each which is failing. This is the spec that is failing. it "raises a RuntimeError if the string is modified while substituting" do str = "hello\nworld" should_raise(RuntimeError) { str.send(cmd) { str[0] = 'x' } } end The idea is that the string that is being iterated over shouldn't be changed during the iteration. It is easy enough to freeze the string in the first line of MutableString.EachLine using: RubyUtils.GetExecutionContext(context).FreezeObject(self); Which appropriately throws an error when the string gets modified, however this approach throws a "TypeError" and the spec wants a "RuntimeError" (message: String#each raises a RuntimeError if the string is modified while substituting FAILED, Expected RuntimeError, got TypeError (can't modify frozen object)). I considered wrapping the code in EachLine that invokes the each block with a try catch and then rethrowing a caught type error exception to a runtime exception however I don't see a runtime exception type in RubyExceptions. Any suggestions on how best to approach this? Thx! rem
_______________________________________________ Ironruby-core mailing list [email protected] http://rubyforge.org/mailman/listinfo/ironruby-core
