Re: How to get the line number in the code?
From: Charles (csw_at_rogers.com)
Date: 10/07/03
- Next message: Phil...: "Re: Queues, prioritization, changing priorities and algorithms"
- Previous message: Lorenzo: "INVIO XML SU HTTP"
- In reply to: Chris: "Re: How to get the line number in the code?"
- Next in thread: Raymond DeCampo: "Re: How to get the line number in the code?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 7 Oct 2003 10:03:04 -0400
Thank you very much for the information. While there is some overhead
involved, it doesn't look like I can get around it. Your solution works fine
and will be put to use.
"Chris" <chris2k01@hotmail.com> wrote in message
news:M5qgb.53644$AC3.1283917@news2.telusplanet.net...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Charles wrote:
>
> > Correct, I wish to be able to do this at runtime. I was hoping for a
> > quick and easy way to do this with minimum overhead.
>
> Hi,
> This is probably far from low-overhead (I've heard exceptions are
> fairly high-overhead, don't know about this), but it does work (if
> your class files are compiled with line numbers):
>
> Throwable t = new Throwable();
> t.fillInStackTrace(); /// WILL FIND NUMBER OF THIS LINE!
> int x = t.getStackTrace()[0].getLineNumber();
>
> As the docs say, if there is no debug info in the class file, you'll
> get a negative number. Of course, if you're trying to find the line
> number of an arbitrary line, it won't work. You can only find the
> line number of a line of code that was designed for the purpose of
> finding that line number.
>
> - --
> Chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.2 (GNU/Linux)
>
> iD8DBQE/gcuAwxczzJRavJYRAveFAKDdm1IprsfTY4bch1xcsypnnRKKXgCgsmIH
> bQ3Yy6y43OjVbG1p/mJDTqQ=
> =bi6b
> -----END PGP SIGNATURE-----
- Next message: Phil...: "Re: Queues, prioritization, changing priorities and algorithms"
- Previous message: Lorenzo: "INVIO XML SU HTTP"
- In reply to: Chris: "Re: How to get the line number in the code?"
- Next in thread: Raymond DeCampo: "Re: How to get the line number in the code?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]