# App vs Engine - raise error message

**URL:** <https://www.ruby-forum.com/t/app-vs-engine-raise-error-message/90270>\
**Category:** Engines\
**Created:** [March 27, 2007, 8:05am UTC](https://www.ruby-forum.com/t/app-vs-engine-raise-error-message/90270 "2007-03-27T08:05:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wes\_Hays](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/db5fbb/32.png) [@Wes\_Hays](https://www.ruby-forum.com/u/Wes_Hays)\
**Post date:** [March 27, 2007, 8:05am UTC](https://www.ruby-forum.com/t/app-vs-engine-raise-error-message/90270/1 "2007-03-27T08:05:47Z")

</div>

I have some code that I was duplicating across applications so I made it  
an engine. The engine works fine but the only problem is when I raise an  
error in the before\_destroy method in my model (the model is not in the  
engine).

Based on the example code below; if I have this code in a controller  
that is not in a engine I will get the following error:

“Fee type is in use”

Which is exactly what I want. However, if I have that exact same code  
in my engine I get the full path to the file that raised the error plus  
the error message “Fee type is in use”.

“/Users/weshays/temp/myapp/config/…/app/models/fee\_type.rb:6:in  
`before\_destroy’: Fee type is in use”

I cannot figure out how to only get the error message without the other  
stuff (path and method) as this could be a possible security risk.

I have tried the different options for the raise method but with no  
luck.

## I am using Ruby 1.8.5 and Rails version 1.2.3. The following sample code is what’s in question.

\*\*\* Model \*\*\*

…

has\_many :ga\_locations

def before\_destroy  
raise ‘Fee type is in use’ if self.ga\_locations.count \> 0  
end

…

\*\*\* Controller \*\*\*

…

begin  
item.destroy  
rescue Exception =\> err  
flash[:error] = err.message  
end

…

* * *

Any help on this would be appreciated.

-Wes

–  
James “Wes” Hays  
Great Basin Development  
P.O.Box 3503, Reno, Nevada 89505  
[http://www.gbdev.com](http://www.gbdev.com)
