Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Explain me printStackTrace??

 
josephine chen
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

//It is printing numbers but what does it exactly do???
[ Jess fixed the [code] block ]
[ March 26, 2003: Message edited by: Jessica Sant ]
 
Lucy C
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The printStackTrace method is a method of the Throwable class - the superclass of all Exceptions. Basically, it just prints out where the Exception in question occurred by giving you the list of method calls that resulted in the Exception being thrown. It's very useful for debugging!
Incidentally, it's got nothing to do with the numbers your code is printing out - they're from the running thread's run method, which is just incrementing i and printing the result...
 
Karin Paola Illuminate
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Do I need to know what the methods fillInStackTrace() and printStackTrace() do for the exam?
Do I also need to know how to throw an object of type Throwable for the exam?
[ March 26, 2003: Message edited by: Karin Paola Illuminate ]
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the exam objectives state:
  • Write code that makes proper use of exceptions and exception handling clauses (try, catch, finally) and declares methods and overriding methods that throw exceptions.
  • Recognize the effect of an exception arising at a specified point in a code fragment. Note: The exception may be a runtime exception, a checked exception, or an error (the code may include try, catch, or finally clauses in any legitimate combination).


  • So... you definitely need to know how to use a try /catch block -- and the finally clause too. You should understand the difference between checked / unchecked exceptions -- (and the basic Exception class hierarchy too).
    However (according to the Sierra/Bates book) For th exam, it is not necessary to know any of the methods contained in the class Throwable... You are expected to know tha Exeption, Error, RuntimeException, and Throwable types can all be thrown using the throws keyword, and can all be caught (although you rarely will catch anything other than Exception subtypes).
     
    Karin Paola Illuminate
    Ranch Hand
    Posts: 109
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Jessica. Thanks.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic