# Adding more details to Exception object

**URL:** <https://www.ruby-forum.com/t/adding-more-details-to-exception-object/128328>\
**Category:** Rails\
**Created:** [February 6, 2008, 8:18pm UTC](https://www.ruby-forum.com/t/adding-more-details-to-exception-object/128328 "2008-02-06T20:18:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [February 6, 2008, 8:18pm UTC](https://www.ruby-forum.com/t/adding-more-details-to-exception-object/128328/1 "2008-02-06T20:18:13Z")

</div>

I know that the default ruby Exception object holds message and  
backtrace.

Sometimes I want to specify variable names and values to the Exception  
object so that I can email myself the details in the exception\_notifier.

I know I could subclass Exception to add more details to it, but I dont  
want to have to recreate all the classes for exceptions that already  
exist (ArgumentError,IOError, etc).

I also know that I could tack on all the info in the message but that  
would get very messy since the message is usually in the subject of my  
error emails.

I want to be able to do :

raise ArgumentError.new(msg, details)

Should I try something like

class Exception  
attr\_accessor :details  
def initialize(msg, details)

end  
end

which probably wont work since its a builtin function and there is only  
stub code for it.

---

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [February 6, 2008, 9:17pm UTC](https://www.ruby-forum.com/t/adding-more-details-to-exception-object/128328/2 "2008-02-06T21:17:39Z")

</div>

Make your own exception:

class CustomException \< StandardError  
attr :message, :details  
def initialize(message, details)  
@message = message  
@details = details  
end  
end

On Feb 6, 11:18 am, Aryk G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
