# Handling errors via mail

**URL:** <https://www.ruby-forum.com/t/handling-errors-via-mail/68931>\
**Category:** Ruby\
**Created:** [September 17, 2006, 1:01am UTC](https://www.ruby-forum.com/t/handling-errors-via-mail/68931 "2006-09-17T01:01:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Radu\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ec9cab/32.png) [@Radu\_S](https://www.ruby-forum.com/u/Radu_S)\
**Post date:** [September 17, 2006, 1:01am UTC](https://www.ruby-forum.com/t/handling-errors-via-mail/68931/1 "2006-09-17T01:01:10Z")

</div>

Hi

I have a small script that runs daemonized and does some basic SQL  
operations.

I was wondering if it possible that in case of an exception the program  
could send an email with the exception, and at the same time log it in  
a file.

I looked over log4r, however I couldn’t get it to log exceptions.

Thanks,  
Radu S.

---

<div class="post-metadata">

**Author:** ![Radu\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ec9cab/32.png) [@Radu\_S](https://www.ruby-forum.com/u/Radu_S)\
**Post date:** [September 17, 2006, 1:15am UTC](https://www.ruby-forum.com/t/handling-errors-via-mail/68931/2 "2006-09-17T01:15:11Z")

</div>

Radu S. wrote:

> I was wondering if it possible that in case of an exception the program  
> could send an email with the exception, and at the same time log it in  
> a file.

Never mind…

begin  
loop do  
# stuff  
sleep 15  
end  
rescue Exception =\> rescueError  
if (rescueError)  
log.fatal rescueError.message  
log.fatal rescueError.backtrace.inspect  
log.fatal ‘---------------------------------’  
end  
end

Radu S.
