473,383 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to get line no Exception occurred at?

I need to get hold of somehow the line no that an exception occurred at so
as to log it using log4j.

My ConversionPattern is set to -

log4j.appender.stdout.layout.ConversionPattern=%5p (%F:%L) - %m%n

but %L only shows the line no that log was called from.

Thought I'd cracked it when I noticed getStackTrace() method of exception
object BUT (notice the big but!), the app must work on 1.3 & getStackTrace()
wasn't introduced until 1.4.

Can I still somehow get hold of the StackTrace & retrieve the line no?

Thanks

harry

Jul 17 '05 #1
3 15133
Try using a PrintWriter, like this:

try {

...

} catch (Exception exception) {
StringWriter stringWriter = new StringWriter();
String stackTrace = null;
exception.printStackTrace(new PrintWriter(stringWriter));

// get the stackTrace as String...
stackTrace = stringWriter.toString();

The line no is usually the found in line 2 of the stacktrace after "java:"
greets
Rolf
Harry wrote:
I need to get hold of somehow the line no that an exception occurred at so
as to log it using log4j.

My ConversionPattern is set to -

log4j.appender.stdout.layout.ConversionPattern=%5p (%F:%L) - %m%n

but %L only shows the line no that log was called from.

Thought I'd cracked it when I noticed getStackTrace() method of exception
object BUT (notice the big but!), the app must work on 1.3 & getStackTrace()
wasn't introduced until 1.4.

Can I still somehow get hold of the StackTrace & retrieve the line no?

Thanks

harry




Jul 17 '05 #2
Cheers Rolf!

"Rolf Rosenbaum" <me@home.org> wrote in message
news:7A*********************@news.easynews.com...
Try using a PrintWriter, like this:

try {

...

} catch (Exception exception) {
StringWriter stringWriter = new StringWriter();
String stackTrace = null;
exception.printStackTrace(new PrintWriter(stringWriter));

// get the stackTrace as String...
stackTrace = stringWriter.toString();

The line no is usually the found in line 2 of the stacktrace after "java:"
greets
Rolf
Harry wrote:
I need to get hold of somehow the line no that an exception occurred at so as to log it using log4j.

My ConversionPattern is set to -

log4j.appender.stdout.layout.ConversionPattern=%5p (%F:%L) - %m%n

but %L only shows the line no that log was called from.

Thought I'd cracked it when I noticed getStackTrace() method of exception object BUT (notice the big but!), the app must work on 1.3 & getStackTrace() wasn't introduced until 1.4.

Can I still somehow get hold of the StackTrace & retrieve the line no?

Thanks

harry



Jul 17 '05 #3
Here is a second example as well :

http://www.javapractices.com/Topic78.cjp

Harry wrote:
I need to get hold of somehow the line no that an exception occurred at so
as to log it using log4j.

My ConversionPattern is set to -

log4j.appender.stdout.layout.ConversionPattern=%5 p (%F:%L) - %m%n

but %L only shows the line no that log was called from.

Thought I'd cracked it when I noticed getStackTrace() method of exception
object BUT (notice the big but!), the app must work on 1.3 & getStackTrace()
wasn't introduced until 1.4.

Can I still somehow get hold of the StackTrace & retrieve the line no?

Thanks

harry



Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: psaban | last post by:
Getting an exception occurred error with the following code: Dim rgstcustConnect 'as Connection set rgstcustConnect=server.createobject("adodb.connection") rgstcustConnect.open...
2
by: chris.higginson | last post by:
Hi, I'm running SQL Server Version 8.00.194 on Windows 2000. I am am running this query: select TOP 2000 TheoVolImplied from OptionTrades where ReutersSymbol = 'IBM.N' and TheoVolImplied...
1
by: Pardhasaradhy | last post by:
Hi, Please see the following error and revert back as early as possible. I am getting this once I request for the asp.net page. Server Error in '/tanishq' Application. Timed out waiting for...
0
by: Marco Viana | last post by:
Hi, I'm developing an ASP.NET application with Visual Studio .NET 2003 in a Win XP Professional, .NET Framework 1.1 and IIS 5.1 computer with all the lattest patches. When testing a page...
6
by: Si | last post by:
I get the following error from the code below: Error Type: (0x80020009) Exception occurred. /diary.asp, line 53 The specific part that causes the exception is when I try to access...
1
by: maidonical | last post by:
I am trying to run "select * from <table> where <columnname> = 0.0" in query analyzer <columnname> is a float I get the following error: Server: Msg 3628, Level 16, State 1, Line 1 A floating...
1
by: Richard Gordon | last post by:
I've got a fatal bug using Parente's pyTTS with Python 2.3 on Windoze 32 using MS SAPI 5.1 and Hammond's win32 module. The test program is import pyTTS tts = pyTTS.Create() tts.Speak('Hello...
1
by: morrisqueto | last post by:
Hello, One of my websites just started sending a new rare error. The site has been working for almost 2 years without trouble, but today morning started giving away this error in all my views. ...
2
by: shivasusan | last post by:
Hi! I got error. Pls check my error. <% dim uname dim pwd uname = Request.Form("txtuname")
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.