[Ironruby-core] TypeError maps to System.InvalidOperationException?

Tomas Matousek Tomas.Matousek at microsoft.com
Wed Jan 21 21:35:38 EST 2009


If you search for "RubyExceptions.CreateTypeError" in libraries you'll get lines including the following (apart from type conversion errors). So it's not always a cast or conversion that fails. On the other hand, a conversion to a wrong type is an invalid operation. The exception mapping is attached.

  C:\M0\Merlin\Main\Languages\Ruby\Ruby\Builtins\MutableString.cs(244):                throw RubyExceptions.CreateTypeError("can't modify frozen object");
  C:\M0\Merlin\Main\Languages\Ruby\Ruby\Builtins\RubyClass.cs(171):                throw RubyExceptions.CreateTypeError("can't copy singleton class");
  C:\M0\Merlin\Main\Languages\Ruby\Ruby\Builtins\RubyClass.cs(183):                throw RubyExceptions.CreateTypeError("already initialized class");
  C:\M0\Merlin\Main\Languages\Ruby\Ruby\Builtins\RubyClass.cs(510):                        throw RubyExceptions.CreateTypeError(String.Format("allocator undefined for {0}", Name));
  C:\M0\Merlin\Main\Languages\Ruby\Ruby\Builtins\RubyClass.cs(592):            throw RubyExceptions.CreateTypeError(String.Format("allocator undefined for {0}", Name));
  C:\M0\Merlin\Main\Languages\Ruby\Ruby\Builtins\RubyModule.cs(355):                throw RubyExceptions.CreateTypeError("can't modify frozen Module");
  C:\M0\Merlin\Main\Languages\Ruby\Ruby\Runtime\Globals\SpecialGlobalVariableInfo.cs(239):                throw RubyExceptions.CreateTypeError(String.Format("${0} must have write method, {1} given",    C:\M0\Merlin\Main\Languages\Ruby\Ruby\Runtime\RubyContext.cs(1321):                throw RubyExceptions.CreateTypeError("assigning non-exception to $!");
  C:\M0\Merlin\Main\Languages\Ruby\Ruby\Runtime\RubyContext.cs(1345):                throw RubyExceptions.CreateTypeError("backtrace must be Array of String");
  C:\M0\Merlin\Main\Languages\Ruby\Ruby\Runtime\RubyExceptions.cs(127):            return RubyExceptions.CreateTypeError(String.Format("{0} can't be coerced into {1}", selfClass, otherClass));
  C:\M0\Merlin\Main\Languages\Ruby\Ruby\Runtime\RubyOps.cs(503):                    throw RubyExceptions.CreateTypeError("can't define singleton method for literals");
  C:\M0\Merlin\Main\Languages\Ruby\Libraries.LCA_RESTRICTED\Builtins\TimeOps.cs(224):                throw RubyExceptions.CreateTypeError("unable to marshal time");
  C:\M0\Merlin\Main\Languages\Ruby\Libraries.LCA_RESTRICTED\Builtins\TimeOps.cs(260):                throw RubyExceptions.CreateTypeError("marshaled time format differ");

From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shri Borde
Sent: Wednesday, January 21, 2009 4:47 PM
To: ironruby-core at rubyforge.org
Subject: [Ironruby-core] TypeError maps to System.InvalidOperationException?

We map Ruby's TypeError to System.InvalidOperationException. This surprised me. I would have expected TypeError to map to System.InvalidCastException. Wouldn't that be preferable?

In general, it would be good to document on http://www.ironruby.net/Documentation/CLR_Interop/Specification the exact mapping of the entire Ruby exception hierarchy to the equivalent .NET exception types. This will be useful documentation, especially for apps that host IronRuby scripts, and we can also do a brief review and potentially tweak the mapping. I have added a table at the bottom of the page which is half filled in.

Thanks,
Shri

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090121/19cde5aa/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ExceptionHierarchy.png
Type: image/png
Size: 56331 bytes
Desc: ExceptionHierarchy.png
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090121/19cde5aa/attachment-0001.png>


More information about the Ironruby-core mailing list