• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Timeout Exception

 
Jeremiah da Costa
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure it's standard out?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Gazoo,"

Welcome to JavaRanch! Please check your private messages by clicking on My Private Messages. Thanks!
 
Bob Ruth
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell! I even looked it up in the API, came right back, and wrote it wrong. It is standard error!!!
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"fdacosta" (previously "Gazoo"),

Please check the JavaRanch Naming Policy, and revise your display name appropriately. Thanks!
 
Jeremiah da Costa
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all on my first post. One day I'll be able to help others as I've been helped.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic