Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Scala have "macro" definitions ready to use -- like LINE, FILE?

Tags:

macros

scala

When you get a stack trace from exception you get files and line numbers. I need something like this for my reporting, so I could get to the cause very fast.

I am looking in particular for LINE and FILE macro. Is there anything like this in Scala?

like image 879
greenoldman Avatar asked Dec 14 '11 20:12

greenoldman


1 Answers

There is no such macro neither in Scala nor in Java. Of course the line number information is stored in the bytecode (also for debugging purposes) but there is no API to obtain it.

Stack traces with class names and line numbers are generated via native Throwable.fillInStackTrace(). Logging libraries might also use Thread.getStackTrace().

In both cases it boils down to parse stack trace and find our current location. Note that generating stack trace is time-consuming and should be avoided.

like image 143
Tomasz Nurkiewicz Avatar answered Oct 21 '22 12:10

Tomasz Nurkiewicz