# NetworkException


```
public abstract class NetworkException extends CronetException
```

<br />

|---|---|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||||||
| ↳ | [kotlin.Throwable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html) |||||
|   | ↳ | [java.lang.Exception](https://developer.android.com/reference/java/lang/Exception.html) ||||
|   |   | ↳ | [java.io.IOException](https://developer.android.com/reference/java/io/IOException.html) |||
|   |   |   | ↳ | [org.chromium.net.CronetException](https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/CronetException) ||
|   |   |   |   | ↳ | [org.chromium.net.NetworkException](https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException) |

Known direct subclasses [QuicException](https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/QuicException)

|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/QuicException` | Subclass of `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException` which contains a detailed [QUIC](https://www.chromium.org/quic) error code from [QuicErrorCode](https://cs.chromium.org/search/?q=symbol:%5CbQuicErrorCode%5Cb). |

*** ** * ** ***

Exception passed to `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest.Callback#onFailed(org.chromium.net.UrlRequest,org.chromium.net.UrlResponseInfo,org.chromium.net.CronetException)` when Cronet fails to process a network request. In this case `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#getErrorCode()` and `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#getCronetInternalErrorCode()` can be used to get more information about the specific type of failure. If `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#getErrorCode()` returns `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#ERROR_QUIC_PROTOCOL_FAILED()`, this exception can be cast to a `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/QuicException` which can provide further details.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#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. |
| `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#ERROR_CONNECTION_CLOSED() = 5` Error code indicating the connection was closed unexpectedly. |
| `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#ERROR_CONNECTION_REFUSED() = 7` Error code indicating the connection attempt was refused. |
| `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#ERROR_CONNECTION_RESET() = 8` Error code indicating the connection was unexpectedly reset. |
| `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#ERROR_CONNECTION_TIMED_OUT() = 6` Error code indicating the connection attempt timed out. |
| `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#ERROR_HOSTNAME_NOT_RESOLVED() = 1` Error code indicating the host being sent the request could not be resolved to an IP address. |
| `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#ERROR_INTERNET_DISCONNECTED() = 2` Error code indicating the device was not connected to any network. |
| `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#ERROR_NETWORK_CHANGED() = 3` Error code indicating that as the request was processed the network configuration changed. |
| `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#ERROR_OTHER() = 11` Error code indicating another type of error was encountered. |
| `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#ERROR_QUIC_PROTOCOL_FAILED() = 10` Error code indicating an error related to the [QUIC](https://www.chromium.org/quic) protocol. |
| `static final int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#ERROR_TIMED_OUT() = 4` Error code indicating a timeout expired. |

| ### Protected constructors |
|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#NetworkException(java.lang.String,java.lang.Throwable)(https://developer.android.com/reference/java/lang/String.html message, https://developer.android.com/reference/java/lang/Throwable.html cause)` Constructs an exception that is caused by a network error. |

| ### Public methods |
|---|---|
| `abstract int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#getCronetInternalErrorCode()()` Returns a Cronet internal error code. |
| `abstract int` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#getErrorCode()()` Returns error code, one of `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#ERROR_HOSTNAME_NOT_RESOLVED()`. |
| `abstract boolean` | `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#immediatelyRetryable()()` Returns `true` if retrying this request right away might succeed, `false` otherwise. |

| ### Inherited methods |
|---|
| From [java.lang.Throwable](https://developer.android.com/reference/java/lang/Throwable.html) |---|---| | `synchronized final void` | `https://developer.android.com/reference/java/lang/Throwable.html#addSuppressed(java.lang.Throwable)(https://developer.android.com/reference/java/lang/Throwable.html p)` | | `synchronized https://developer.android.com/reference/java/lang/Throwable.html` | `https://developer.android.com/reference/java/lang/Throwable.html#fillInStackTrace()()` | | `synchronized https://developer.android.com/reference/java/lang/Throwable.html` | `https://developer.android.com/reference/java/lang/Throwable.html#getCause()()` | | `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/java/lang/Throwable.html#getLocalizedMessage()()` | | `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/java/lang/Throwable.html#getMessage()()` | | `StackTraceElement[]` | `https://developer.android.com/reference/java/lang/Throwable.html#getStackTrace()()` | | `synchronized final Throwable[]` | `https://developer.android.com/reference/java/lang/Throwable.html#getSuppressed()()` | | `synchronized https://developer.android.com/reference/java/lang/Throwable.html` | `https://developer.android.com/reference/java/lang/Throwable.html#initCause(java.lang.Throwable)(https://developer.android.com/reference/java/lang/Throwable.html p)` | | `void` | `https://developer.android.com/reference/java/lang/Throwable.html#printStackTrace()()` | | `void` | `https://developer.android.com/reference/java/lang/Throwable.html#setStackTrace(java.lang.StackTraceElement[])(StackTraceElement[] p)` | | `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/java/lang/Throwable.html#toString()()` | |

## 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 `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#getErrorCode()` returns this code, this exception may be cast to `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/QuicException` for more information if [QUIC](https://www.chromium.org/quic) protocol is used.

### ERROR_OTHER

```
public static final int ERROR_OTHER = 11
```

Error code indicating another type of error was encountered. `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#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](https://www.chromium.org/quic) protocol. When `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#getErrorCode()` returns this code, this exception can be cast to `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/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 `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#ERROR_CONNECTION_TIMED_OUT()`.

## Protected constructors

### NetworkException

```
protected NetworkException(String message, Throwable cause)
```

Constructs an exception that is caused by a network error.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html message` | explanation of failure. |
| `https://developer.android.com/reference/java/lang/Throwable.html cause` | the cause (which is saved for later retrieval by the `https://developer.android.com/reference/java/lang/Throwable.html#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 `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#getErrorCode()`, but the constant values are not exposed to Java and may change over time. See [here](https://chromium.googlesource.com/chromium/src/+/main/net/base/net_error_list.h) for the lastest list of values.

| Returns |
|---|---|
| `int` | Cronet internal error code. |

### getErrorCode

```
public abstract int getErrorCode()
```

Returns error code, one of `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#ERROR_HOSTNAME_NOT_RESOLVED()`.

| Returns |
|---|---|
| `int` | error code, one of `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#ERROR_HOSTNAME_NOT_RESOLVED()`. |

### immediatelyRetryable

```
public abstract boolean immediatelyRetryable()
```

Returns `true` if retrying this request right away might succeed, `false` otherwise. For example returns `true` when `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#getErrorCode()` returns `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#ERROR_NETWORK_CHANGED()` because trying the request might succeed using the new network configuration, but `false` when `getErrorCode()` returns `https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/NetworkException#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. |