NetworkException

public abstract class NetworkException extends CronetException

Known direct subclasses
QuicException

Subclass of NetworkException which contains a detailed QUIC error code from QuicErrorCode.


Exception passed to UrlRequest.Callback.onFailed() when Cronet fails to process a network request. In this case getErrorCode and getCronetInternalErrorCode can be used to get more information about the specific type of failure. If getErrorCode returns ERROR_QUIC_PROTOCOL_FAILED, this exception can be cast to a QuicException which can provide further details.

Summary

Constants

static final int

Error code indicating the IP address being contacted is unreachable, meaning there is no route to the specified host or network.

static final int

Error code indicating the connection was closed unexpectedly.

static final int

Error code indicating the connection attempt was refused.

static final int

Error code indicating the connection was unexpectedly reset.

static final int

Error code indicating the connection attempt timed out.

static final int

Error code indicating the host being sent the request could not be resolved to an IP address.

static final int

Error code indicating the device was not connected to any network.

static final int

Error code indicating that as the request was processed the network configuration changed.

static final int

Error code indicating another type of error was encountered.

static final int

Error code indicating an error related to the QUIC protocol.

static final int

Error code indicating a timeout expired.

Protected constructors

NetworkException(String message, Throwable cause)

Constructs an exception that is caused by a network error.

Public methods

abstract int

Returns a Cronet internal error code.

abstract int

Returns error code, one of ERROR_*.

abstract boolean

Returns true if retrying this request right away might succeed, false otherwise.

Inherited methods

From java.lang.Throwable
synchronized final void
synchronized Throwable
synchronized Throwable
String
String
StackTraceElement[]
synchronized final Throwable[]
synchronized Throwable
void
void
setStackTrace(StackTraceElement[] p)
String

Constants

ERROR_ADDRESS_UNREACHABLE

public static final int ERROR_ADDRESS_UNREACHABLE = 9

Error code indicating the IP address being contacted is unreachable, meaning there is no route to the specified host or network.

ERROR_CONNECTION_CLOSED

public static final int ERROR_CONNECTION_CLOSED = 5

Error code indicating the connection was closed unexpectedly.

ERROR_CONNECTION_REFUSED

public static final int ERROR_CONNECTION_REFUSED = 7

Error code indicating the connection attempt was refused.

ERROR_CONNECTION_RESET

public static final int ERROR_CONNECTION_RESET = 8

Error code indicating the connection was unexpectedly reset.

ERROR_CONNECTION_TIMED_OUT

public static final int ERROR_CONNECTION_TIMED_OUT = 6

Error code indicating the connection attempt timed out.

ERROR_HOSTNAME_NOT_RESOLVED

public static final int ERROR_HOSTNAME_NOT_RESOLVED = 1

Error code indicating the host being sent the request could not be resolved to an IP address.

ERROR_INTERNET_DISCONNECTED

public static final int ERROR_INTERNET_DISCONNECTED = 2

Error code indicating the device was not connected to any network.

ERROR_NETWORK_CHANGED

public static final int ERROR_NETWORK_CHANGED = 3

Error code indicating that as the request was processed the network configuration changed. When getErrorCode returns this code, this exception may be cast to QuicException for more information if QUIC protocol is used.

ERROR_OTHER

public static final int ERROR_OTHER = 11

Error code indicating another type of error was encountered. getCronetInternalErrorCode can be consulted to get a more specific cause.

ERROR_QUIC_PROTOCOL_FAILED

public static final int ERROR_QUIC_PROTOCOL_FAILED = 10

Error code indicating an error related to the QUIC protocol. When getErrorCode returns this code, this exception can be cast to QuicException for more information.

ERROR_TIMED_OUT

public static final int ERROR_TIMED_OUT = 4

Error code indicating a timeout expired. Timeouts expiring while attempting to connect will be reported as the more specific ERROR_CONNECTION_TIMED_OUT.

Protected constructors

NetworkException

protected NetworkException(String message, Throwable cause)

Constructs an exception that is caused by a network error.

Parameters
String message

explanation of failure.

Throwable cause

the cause (which is saved for later retrieval by the getCause() method). A null value is permitted, and indicates that the cause is nonexistent or unknown.

Public methods

getCronetInternalErrorCode

public abstract int getCronetInternalErrorCode()

Returns a Cronet internal error code. This may provide more specific error diagnosis than getErrorCode, but the constant values are not exposed to Java and may change over time. See here for the lastest list of values.

Returns
int

Cronet internal error code.

getErrorCode

public abstract int getErrorCode()

Returns error code, one of ERROR_*.

Returns
int

error code, one of ERROR_*.

immediatelyRetryable

public abstract boolean immediatelyRetryable()

Returns true if retrying this request right away might succeed, false otherwise. For example returns true when getErrorCode returns ERROR_NETWORK_CHANGED because trying the request might succeed using the new network configuration, but false when getErrorCode() returns ERROR_INTERNET_DISCONNECTED because retrying the request right away will encounter the same failure (instead retrying should be delayed until device regains network connectivity).

Returns
boolean

true if retrying this request right away might succeed, false otherwise.