twitter4j
Class TwitterException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by twitter4j.TwitterException
All Implemented Interfaces:
java.io.Serializable

public class TwitterException
extends java.lang.Exception

An exception class that will be thrown when TwitterAPI calls are failed.
In case the Twitter server returned HTTP error code, you can get the HTTP status code using getStatusCode() method.

Author:
Yusuke Yamamoto - yusuke at mac.com
See Also:
Serialized Form

Field Summary
private  int retryAfter
           
private static long serialVersionUID
           
private  int statusCode
           
 
Constructor Summary
TwitterException(java.lang.Exception cause)
           
TwitterException(java.lang.String msg)
           
TwitterException(java.lang.String msg, java.lang.Exception cause)
           
TwitterException(java.lang.String msg, java.lang.Exception cause, int statusCode)
           
TwitterException(java.lang.String msg, int statusCode)
           
 
Method Summary
static TwitterException createRateLimitedTwitterException(java.lang.String msg, int statusCode, int retryAfter)
           
 int getRetryAfter()
          Returns int value of "Retry-After" response header.
 int getStatusCode()
           
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

statusCode

private int statusCode

retryAfter

private int retryAfter

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

TwitterException

public TwitterException(java.lang.String msg)

TwitterException

public TwitterException(java.lang.Exception cause)

TwitterException

public TwitterException(java.lang.String msg,
                        int statusCode)

TwitterException

public TwitterException(java.lang.String msg,
                        java.lang.Exception cause)

TwitterException

public TwitterException(java.lang.String msg,
                        java.lang.Exception cause,
                        int statusCode)
Method Detail

createRateLimitedTwitterException

public static TwitterException createRateLimitedTwitterException(java.lang.String msg,
                                                                 int statusCode,
                                                                 int retryAfter)

getStatusCode

public int getStatusCode()

getRetryAfter

public int getRetryAfter()
Returns int value of "Retry-After" response header. An application that exceeds the rate limitations of the Search API will receive HTTP 503 response codes to requests.
It is a best practice to watch for this error condition and honor the Retry-After header that instructs the application when it is safe to continue. The Retry-After header's value is the number of seconds your application should wait before submitting another query.
(for example: Retry-After: 67).
Check if getStatusCode() == 503 before calling this method to ensure that you are actually exceeding rate limitation with query apis.
Otherwise, you'll get an IllegalStateException if "Retry-After" response header was not included in the response.

Returns:
instructs the application when it is safe to continue in seconds
Since:
Twitter4J 2.1.0
See Also:
Rate limiting