# How to log the line in which the error/exception occurred?

**URL:** <https://www.ruby-forum.com/t/how-to-log-the-line-in-which-the-error-exception-occurred/143596>\
**Category:** Ruby\
**Created:** [July 21, 2008, 2:05am UTC](https://www.ruby-forum.com/t/how-to-log-the-line-in-which-the-error-exception-occurred/143596 "2008-07-21T02:05:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [July 21, 2008, 2:05am UTC](https://www.ruby-forum.com/t/how-to-log-the-line-in-which-the-error-exception-occurred/143596/1 "2008-07-21T02:05:18Z")

</div>

Hi, I log errors/exception into a Thread in this way:

```
                   Thread.new {

```

Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â begin  
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Logic::process(data)  
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rescue =\> e  
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â puts “#{e.class}: #{$!}”  
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â end  
Â Â Â Â Â Â Â Â Â Â Â Â }

but it doesn’t show in which file and line the problem occurs, how to  
show it?

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [July 21, 2008, 2:08am UTC](https://www.ruby-forum.com/t/how-to-log-the-line-in-which-the-error-exception-occurred/143596/2 "2008-07-21T02:08:48Z")

</div>

El Lunes, 21 de Julio de 2008, IÃ±aki Baz C. escribiÃ³:

> but it doesn’t show in which file and line the problem occurs, how to show  
> it?
> 
> Thanks a lot.

The solution is:

puts $!.backtrace

🙂
