twitter4j

## Class TwitterException

- java.lang.Object
- - java.lang.Throwable
  - - java.lang.Exception
    - - twitter4j.TwitterException

All Implemented Interfaces:
  Serializable, HttpResponseCode, TwitterResponse

    public class TwitterException
    extends Exception
    implements TwitterResponse, HttpResponseCode

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

### Fields inherited from interface twitter4j.TwitterResponse

`NONE, READ, READ_WRITE, READ_WRITE_DIRECTMESSAGES`

### Fields inherited from interface twitter4j.HttpResponseCode

`BAD_GATEWAY, BAD_REQUEST, ENHANCE_YOUR_CLAIM, FORBIDDEN, FOUND, GATEWAY_TIMEOUT, INTERNAL_SERVER_ERROR, MULTIPLE_CHOICES, NOT_ACCEPTABLE, NOT_FOUND, NOT_MODIFIED, OK, SERVICE_UNAVAILABLE, TOO_MANY_REQUESTS, UNAUTHORIZED, UNPROCESSABLE_ENTITY`

### Constructor Summary

Constructors
Constructor and Description
`TwitterException(Exception cause)`
`TwitterException(String message)`
`TwitterException(String message, Exception cause, int statusCode)`
`TwitterException(String message, HttpResponse res)`
`TwitterException(String message, Throwable cause)`

### Method Summary

All Methods Instance Methods Concrete Methods
`boolean` `equals(Object o)`
`boolean` `exceededRateLimitation()` Tests if the exception is caused by rate limitation exceed
`int` `getAccessLevel()`
`int` `getErrorCode()`
`String` `getErrorMessage()` Returns error message from the API if available.

`String`

`getExceptionCode()`
Returns a hexadecimal representation of this exception stacktrace.
An exception code is a hexadecimal representation of the stacktrace which enables it easier to Google known issues.
Format : XXXXXXXX:YYYYYYYY[ XX:YY]
Where XX is a hash code of stacktrace without line number
YY is a hash code of stacktrace excluding line number
[-XX:YY] will appear when this instance a root cause

`String` `getMessage()`
`RateLimitStatus` `getRateLimitStatus()` Returns the current rate limit status if available.
`String` `getResponseHeader(String name)`
`int` `getRetryAfter()` Returns int value of "Retry-After" response header (Search API) or seconds_until_reset (REST API).
`int` `getStatusCode()`
`int` `hashCode()`
`boolean` `isCausedByNetworkIssue()` Tests if the exception is caused by network issue
`boolean` `isErrorMessageAvailable()` Tests if error message from the API is available
`boolean` `resourceNotFound()` Tests if the exception is caused by non-existing resource
`String` `toString()`

### Methods inherited from class java.lang.Throwable

`addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace`

### Methods inherited from class java.lang.Object

`getClass, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### TwitterException

    public TwitterException(String message,
                            Throwable cause)

#### TwitterException

    public TwitterException(String message)

#### TwitterException

    public TwitterException(Exception cause)

#### TwitterException

    public TwitterException(String message,
                            HttpResponse res)

#### TwitterException

    public TwitterException(String message,
                            Exception cause,
                            int statusCode)

### Method Detail

#### getMessage

    public String getMessage()

Overrides:
  `getMessage` in class `Throwable`

#### getStatusCode

    public int getStatusCode()

#### getErrorCode

    public int getErrorCode()

#### getResponseHeader

    public String getResponseHeader(String name)

#### getRateLimitStatus

    public RateLimitStatus getRateLimitStatus()

Description copied from interface: `TwitterResponse`
Returns the current rate limit status if available.

Specified by:
  `getRateLimitStatus` in interface `TwitterResponse`
Returns:
  current rate limit status

#### getAccessLevel

    public int getAccessLevel()

Specified by:
  `getAccessLevel` in interface `TwitterResponse`
Returns:
  application permission model
See Also:
  Application Permission Model FAQ - How do we know what the access level of a user token is?

#### getRetryAfter

    public int getRetryAfter()

Returns int value of "Retry-After" response header (Search API) or seconds_until_reset (REST API). An application that exceeds the rate limitations of the Search API will receive HTTP 420 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.

Returns:
  instructs the application when it is safe to continue in seconds
Since:
  Twitter4J 2.1.0
See Also:
  Rate Limiting | Twitter Developers

#### isCausedByNetworkIssue

    public boolean isCausedByNetworkIssue()

Tests if the exception is caused by network issue

Returns:
  if the exception is caused by network issue
Since:
  Twitter4J 2.1.2

#### exceededRateLimitation

    public boolean exceededRateLimitation()

Tests if the exception is caused by rate limitation exceed

Returns:
  if the exception is caused by rate limitation exceed
Since:
  Twitter4J 2.1.2
See Also:
  Rate Limiting | Twitter Developers

#### resourceNotFound

    public boolean resourceNotFound()

Tests if the exception is caused by non-existing resource

Returns:
  if the exception is caused by non-existing resource
Since:
  Twitter4J 2.1.2

#### getExceptionCode

    public String getExceptionCode()

Returns a hexadecimal representation of this exception stacktrace.
An exception code is a hexadecimal representation of the stacktrace which enables it easier to Google known issues.
Format : XXXXXXXX:YYYYYYYY[ XX:YY]
Where XX is a hash code of stacktrace without line number
YY is a hash code of stacktrace excluding line number
[-XX:YY] will appear when this instance a root cause

Returns:
  a hexadecimal representation of this exception stacktrace

#### getErrorMessage

    public String getErrorMessage()

Returns error message from the API if available.

Returns:
  error message from the API
Since:
  Twitter4J 2.2.3

#### isErrorMessageAvailable

    public boolean isErrorMessageAvailable()

Tests if error message from the API is available

Returns:
  true if error message from the API is available
Since:
  Twitter4J 2.2.3

#### equals

    public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`

#### toString

    public String toString()

Overrides:
  `toString` in class `Throwable`