# Where would i put a home-made exception class in rails?

**URL:** <https://www.ruby-forum.com/t/where-would-i-put-a-home-made-exception-class-in-rails/114914>\
**Category:** Rails\
**Created:** [September 18, 2007, 7:39pm UTC](https://www.ruby-forum.com/t/where-would-i-put-a-home-made-exception-class-in-rails/114914 "2007-09-18T19:39:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 18, 2007, 7:39pm UTC](https://www.ruby-forum.com/t/where-would-i-put-a-home-made-exception-class-in-rails/114914/1 "2007-09-18T19:39:53Z")

</div>

I’m a bit unsure about the structure of rails…if i make my own class  
for something, eg an exception class extending StandardError, where does  
that class live?

thanks  
max

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 18, 2007, 8:33pm UTC](https://www.ruby-forum.com/t/where-would-i-put-a-home-made-exception-class-in-rails/114914/2 "2007-09-18T20:33:33Z")

</div>

On 9/18/07, Max W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m a bit unsure about the structure of rails…if i make my own class  
> for something, eg an exception class extending StandardError, where does  
> that class live?

The source file should go into the lib/ directory. That directory is  
automatically added to $LOAD\_PATH by the Rails initialization process.  
You can “require” the file in several ways:

1. Use a require statement at the point of need.

2. Add a require statement to config/environment.rb

3. Take advantage of rails’ magic auto-loading gizmo that will  
automatically load some\_class.rb if you reference SomeClass and it’s  
not already defined.

See also:

[http://toolmantim.com/article/2006/12/27/environments\_and\_the\_rails\_initialisation\_process](http://toolmantim.com/article/2006/12/27/environments_and_the_rails_initialisation_process)

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 18, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/where-would-i-put-a-home-made-exception-class-in-rails/114914/3 "2007-09-18T23:09:05Z")

</div>

Bob S. wrote:

> On 9/18/07, Max W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I’m a bit unsure about the structure of rails…if i make my own class  
> > for something, eg an exception class extending StandardError, where does  
> > that class live?
> 
> The source file should go into the lib/ directory. That directory is  
> automatically added to $LOAD\_PATH by the Rails initialization process.  
> You can “require” the file in several ways:
> 
> 1. Use a require statement at the point of need.
> 
> 2. Add a require statement to config/environment.rb
> 
> 3. Take advantage of rails’ magic auto-loading gizmo that will  
> automatically load some\_class.rb if you reference SomeClass and it’s  
> not already defined.
> 
> See also:
> 
> [http://toolmantim.com/article/2006/12/27/environments\_and\_the\_rails\_initialisation\_process](http://toolmantim.com/article/2006/12/27/environments_and_the_rails_initialisation_process)

aha - great advice, nice link as well. There’s stuff in environment  
that i use but don’t really get (never a good situation).

Many thanks!
