Re: Raising Exceptions

And to add further confusion there are also
RubyExceptions.CreateXXXError
methods available.

What to use?

Pete

Peter Bacon D.:

And to add further confusion there are also
RubyExceptions.CreateXXXError methods available.

What to use?

I think the convention is to use the RubyExceptions.CreateXXXError
methods (although I’m not clear on the reason).

  • John

John M.:

Peter Bacon D.:

And to add further confusion there are also
RubyExceptions.CreateXXXError methods available.

What to use?

I think the convention is to use the RubyExceptions.CreateXXXError
methods (although I’m not clear on the reason).

It’s so that you can think in terms of Ruby errors and not what the .NET
exception type should be (IOW you don’t need to read the diagram each
time).

-John

Yes, use RubyExceptions where possible. Otherwise just throw
corresponding BCL exception. We may enrich RubyException class with more
commonly thrown exceptions. When we do so, we will search and replace
affected throws across the library - that’s easy. So if you don’t find
the exception that should be thrown in this class feel free to just
throw the BCL exception directly. The reasons for using RubyExceptions
are clarity, code reuse and consistency in error messages.
RubyExceptions class should be one of the few places where Ruby to BCL
exception mapping takes place - methods on RubyExceptions should be
named after Ruby exception classes, so the library writer doesn’t need
to think about the mapping. The class needs some refactoring though and
it should probably be moved to the library. It’s on my TODO list to do
so.

Tomas

Thanks all for the clarification. Will redo the code I have been
writing to
use RubyExceptions where possible.
Cheers,
Pete

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs