# Re: Raising Exceptions

**URL:** <https://www.ruby-forum.com/t/re-raising-exceptions/122311>\
**Category:** IronRuby\
**Created:** [December 6, 2007, 2:57pm UTC](https://www.ruby-forum.com/t/re-raising-exceptions/122311 "2007-12-06T14:57:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![editkid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@editkid](https://www.ruby-forum.com/u/editkid)\
**Post date:** [December 6, 2007, 2:57pm UTC](https://www.ruby-forum.com/t/re-raising-exceptions/122311/1 "2007-12-06T14:57:55Z")

</div>

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

What to use?

Pete

---

<div class="post-metadata">

**Author:** ![editkid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@editkid](https://www.ruby-forum.com/u/editkid)\
**Post date:** [December 6, 2007, 8:11pm UTC](https://www.ruby-forum.com/t/re-raising-exceptions/122311/2 "2007-12-06T20:11:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![editkid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@editkid](https://www.ruby-forum.com/u/editkid)\
**Post date:** [December 6, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/re-raising-exceptions/122311/3 "2007-12-06T20:27:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![editkid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@editkid](https://www.ruby-forum.com/u/editkid)\
**Post date:** [December 6, 2007, 8:33pm UTC](https://www.ruby-forum.com/t/re-raising-exceptions/122311/4 "2007-12-06T20:33:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![editkid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@editkid](https://www.ruby-forum.com/u/editkid)\
**Post date:** [December 6, 2007, 8:42pm UTC](https://www.ruby-forum.com/t/re-raising-exceptions/122311/5 "2007-12-06T20:42:29Z")

</div>

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