aspose file tools*
The moose likes Beginning Java and the fly likes Timeout Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Timeout Exception" Watch "Timeout Exception" New topic
Author

Timeout Exception

Jeremiah da Costa
Greenhorn

Joined: Nov 29, 2007
Posts: 12
Need help with the following:

catch (TimeoutException e) {
e.printStackTrace();
}

Does this catch the exception to variable e and then what does this print to?
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
...interpreting this as just a code snippet that focuses on your question,

e is a variable of type TimeoutException being specified as a parameter to your catch clause. If code running earlier in a "try block" happened to take a TimeoutException, a TimeoutException object would be instantiated, initialized and the catch() handler would receive that object as "e".
The single line in the handler, e.printStackTrace(), calls the method printStackTrace() in the exception object. This causes the object to print a stack trace ( a way to "walk back" through the method calls that got you here... ) to the console. According to the API, it prints this stack trace to standard out.


------------------------
Bob
SCJP - 86% - June 11, 2009
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
Welcome to the Ranch.

Well, sort of, yes. A catch block looks a bit like a little method; it has a parameter which it catches, and yes, you are applying the name "e" to any TimeoutExceptions you might catch.
The printStackTrace() method is about the simplest action you can take in response to an Exception; it usually prints to the "standard error stream" (or wherever System.err happens to be pointing). It is actually inherited from the Throwable class. See the API specification for Exception (you can easily find a link to Throwable at the top of the web page), and the Java Tutorial about Exceptions.

I would warn you however that different people have different opinions about Exceptions.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
Are you sure it's standard out?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

"Gazoo,"

Welcome to JavaRanch! Please check your private messages by clicking on My Private Messages. Thanks!


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
Thanks Campbell! I even looked it up in the API, came right back, and wrote it wrong. It is standard error!!!
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

"fdacosta" (previously "Gazoo"),

Please check the JavaRanch Naming Policy, and revise your display name appropriately. Thanks!
Jeremiah da Costa
Greenhorn

Joined: Nov 29, 2007
Posts: 12
Thanks to all on my first post. One day I'll be able to help others as I've been helped.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Timeout Exception