Questions tagged [printstacktrace]

71 questions
425
votes
7 answers

How to print the current Stack Trace in .NET without any exception?

I have a regular C# code. I have no exceptions. I want to programmatically log the current stack trace for debugging purpose. Example: public void executeMethod() { logStackTrace(); method(); }
Ricibald
  • 9,369
  • 7
  • 47
  • 62
142
votes
9 answers

Why is exception.printStackTrace() considered bad practice?

There is a lot of material out there which suggests that printing the stack trace of an exception is bad practice. E.g. from the RegexpSingleline check in Checkstyle: This check can be used [...] to find common bad practice such as calling…
Chris Knight
  • 24,333
  • 24
  • 88
  • 134
113
votes
7 answers

Avoid printStackTrace(); use a logger call instead

In my application, I am running my code through PMD.It shows me this message: Avoid printStackTrace(); use a logger call instead. What does that mean?
user1305398
  • 3,550
  • 5
  • 26
  • 42
107
votes
9 answers

What is the use of printStackTrace() method in Java?

I am going through a socket program. In it, printStackTrace is called on the IOException object in the catch block. What does printStackTrace() actually do? catch(IOException ioe) { ioe.printStackTrace(); } I am unaware of its purpose. What is…
Venkat
  • 20,802
  • 26
  • 75
  • 84
65
votes
5 answers

Using e.printStackTrace() in Java

This is probably a newbie question, but hope you can help me. :) I have something like this: try { //try to do something there } catch (IOException e) { //handle the exception e.printStackTrace(); } I am using NetBeans IDE and for some reason the…
O_O
  • 4,397
  • 18
  • 54
  • 69
61
votes
5 answers

Is it a bad idea to use printStackTrace() for caugt Exceptions?

Is it a bad idea to use printStackTrace() in Android Exceptions like this? } catch (Exception e) { e.printStackTrace(); }
jacknad
  • 13,483
  • 40
  • 124
  • 194
36
votes
8 answers

printStackTrace to java.util.logging.Logger

How do I print the entire stack trace using java.util.Logger? (without annoying Netbeans). The question should've originally specified staying within Java SE. Omitting that requirment was an error on my part. -do-compile: [mkdir] Created dir:…
Thufir
  • 8,216
  • 28
  • 125
  • 273
15
votes
4 answers

How do I get ruby to print a full backtrace that includes arguments passed to functions?

Sometimes backtrace is enough to diagnose problem. But sometimes reason of crash is not obvious without knowledge what was passed to function. Getting information what was passed to function that caused crash would be quite useful, especially in…
reducing activity
  • 1,985
  • 2
  • 36
  • 64
13
votes
6 answers

Get stacktrace as string

I'm using Clojure and I want to get my hands on a stack trace that I can log (ideally, i would like to get it as a String). I see that (.getStackTrace e) returns a StackTraceElement[] but I don't know how to print something meaningful out of it. My…
sebi
  • 1,791
  • 3
  • 25
  • 43
10
votes
2 answers

Override Logback error output

In my custom exception class I've overridden toString(): @Override public String toString() { final String msg = getLocalizedMessage(); // base String str = getClass().getName() + ": [" + code + "]"; // message if (msg !=…
Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301
8
votes
3 answers

How to generate javascript stacktrace?

Any suggestions on how to, in a cross-browser way, generate a stack trace in javascript? Newer browsers, Chrome and Firefox, expose a console object that allows stack traces to be generated. This method does not provide a method for storing the…
Kyle
  • 1,019
  • 1
  • 10
  • 19
6
votes
3 answers

Getting the Stacktrace

When Exception happens you can print out the StackTrace and review it. What if you want to get the StackTrace without an exception happening? Is there a way to do this?
Debbi
6
votes
1 answer

Why some stacktrace do not have line number in java

I have a bug from my customer and when I look into the log we trace the exception, some of the stacktrace do not have line number: at xxxx.xxx.xx.x.xx.DayIntervalRule.getInterval(DayIntervalRule.java) at…
JaskeyLam
  • 15,405
  • 21
  • 114
  • 149
6
votes
1 answer

Why does the execution order between the printStackTrace() and the other methods appear to be nondeterministic?

In my code snippet below, the printStackTrace() method is called in the catch block. After running the program you can see that sometimes the printStackTrace() runs several times in a row instead of running in the order of printStackTrace() -->…
Laz London
  • 302
  • 1
  • 3
  • 11
6
votes
3 answers

Correct way to handle Exception Stack Traces in Python

I am writing some code which can generate Exceptions deep in the stack, and I have a layer nearer the top which catches these exceptions and sends them off for processing by an error handling module. What I would like is for the error handling…
Richard J
  • 6,883
  • 4
  • 22
  • 27
1
2 3 4 5