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

Shri Borde Shri.Borde at microsoft.com
Thu Jan 22 01:04:21 EST 2009

All exceptions are invalid operations of some sort, and you could potentially want to use InvalidOperationException for any Ruby exception which did not map well to a CLR exception. I think picking either InvalidCastException or TypeLoadException would be better as it would be a bit more specific. And an InvalidCastException caused in C# code would be displayed as a TypeError in Ruby which would be nice. But given that neither InvalidCastException or TypeLoadException are a perfect match for TypeError, I won't push on this if everyone is OK with the current mapping.

Btw, the image is cool. I have attached it to http://www.ironruby.net/Documentation/CLR_Interop/Specification.

From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Tomas Matousek
Sent: Wednesday, January 21, 2009 6:36 PM
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] TypeError maps to System.InvalidOperationException?

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.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090121/4d15e3e7/attachment.html>

More information about the Ironruby-core mailing list