# NetworkException


```
abstract class NetworkException : CronetException
```

<br />

|---|---|---|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.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/kotlin/org/chromium/net/CronetException) ||
|   |   |   |   | ↳ | [org.chromium.net.NetworkException](https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/NetworkException) |

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

|---|---|
| `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/QuicException` | Subclass of `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/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/kotlin/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/kotlin/org/chromium/net/NetworkException#getErrorCode()` and `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/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/kotlin/org/chromium/net/NetworkException#getErrorCode()` returns `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/NetworkException#ERROR_QUIC_PROTOCOL_FAILED()`, this exception can be cast to a `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/QuicException` which can provide further details.

## Summary

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

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

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

| ### Inherited functions |
|---|
| From [java.lang.Throwable](https://developer.android.com/reference/java/lang/Throwable.html) |---|---| | `synchronized https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/add-suppressed.html(p: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html!)` | | `synchronized https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html!` | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/fill-in-stack-trace.html()` | | `synchronized https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html!` | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/get-cause.html()` | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!` | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/get-localized-message.html()` | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!` | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/get-message.html()` | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html<https://developer.android.com/reference/java/lang/StackTraceElement.html!>!` | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/get-stack-trace.html()` | | `synchronized https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html!>!` | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/get-suppressed.html()` | | `synchronized https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html!` | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/init-cause.html(p: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html!)` | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/print-stack-trace.html()` | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/set-stack-trace.html(p: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html<https://developer.android.com/reference/java/lang/StackTraceElement.html!>!)` | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!` | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/to-string.html()` | |

## Constants

### ERROR_ADDRESS_UNREACHABLE

```
const val ERROR_ADDRESS_UNREACHABLE = 9: Int
```

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

### ERROR_CONNECTION_CLOSED

```
const val ERROR_CONNECTION_CLOSED = 5: Int
```

Error code indicating the connection was closed unexpectedly.

### ERROR_CONNECTION_REFUSED

```
const val ERROR_CONNECTION_REFUSED = 7: Int
```

Error code indicating the connection attempt was refused.

### ERROR_CONNECTION_RESET

```
const val ERROR_CONNECTION_RESET = 8: Int
```

Error code indicating the connection was unexpectedly reset.

### ERROR_CONNECTION_TIMED_OUT

```
const val ERROR_CONNECTION_TIMED_OUT = 6: Int
```

Error code indicating the connection attempt timed out.

### ERROR_HOSTNAME_NOT_RESOLVED

```
const val ERROR_HOSTNAME_NOT_RESOLVED = 1: Int
```

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

### ERROR_INTERNET_DISCONNECTED

```
const val ERROR_INTERNET_DISCONNECTED = 2: Int
```

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

### ERROR_NETWORK_CHANGED

```
const val ERROR_NETWORK_CHANGED = 3: Int
```

Error code indicating that as the request was processed the network configuration changed. When `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/NetworkException#getErrorCode()` returns this code, this exception may be cast to `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/QuicException` for more information if [QUIC](https://www.chromium.org/quic) protocol is used.

### ERROR_OTHER

```
const val ERROR_OTHER = 11: Int
```

Error code indicating another type of error was encountered. `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/NetworkException#getCronetInternalErrorCode()` can be consulted to get a more specific cause.

### ERROR_QUIC_PROTOCOL_FAILED

```
const val ERROR_QUIC_PROTOCOL_FAILED = 10: Int
```

Error code indicating an error related to the [QUIC](https://www.chromium.org/quic) protocol. When `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/NetworkException#getErrorCode()` returns this code, this exception can be cast to `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/QuicException` for more information.

### ERROR_TIMED_OUT

```
const val ERROR_TIMED_OUT = 4: Int
```

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/kotlin/org/chromium/net/NetworkException#ERROR_CONNECTION_TIMED_OUT()`.

## Protected constructors

### NetworkException

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

Constructs an exception that is caused by a network error.

| Parameters |
|---|---|
| `message: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html!` | explanation of failure. |
| `cause: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html!` | 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 functions

### getCronetInternalErrorCode

```
abstract fun getCronetInternalErrorCode(): Int
```

Returns a Cronet internal error code. This may provide more specific error diagnosis than `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/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 |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | Cronet internal error code. |

### getErrorCode

```
abstract fun getErrorCode(): Int
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | error code, one of `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/org/chromium/net/NetworkException#ERROR_HOSTNAME_NOT_RESOLVED()`. |

### immediatelyRetryable

```
abstract fun immediatelyRetryable(): Boolean
```

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/kotlin/org/chromium/net/NetworkException#getErrorCode()` returns `https://developer.android.com/develop/connectivity/cronet/reference/kotlin/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/kotlin/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 |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `true` if retrying this request right away might succeed, `false` otherwise. |