# DataSourceException

Artifact: [androidx.media3:media3-datasource](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/datasource/DataSourceException.java+class:androidx.media3.datasource.DataSourceException)

*** ** * ** ***


```
class DataSourceException : IOException
```

<br />

|---|---|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||||
| ↳ | [kotlin.Throwable](https://kotlinlang.org/api/core/kotlin-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) ||
|   |   |   | ↳ | [androidx.media3.datasource.DataSourceException](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceException) |

Known direct subclasses [AssetDataSource.AssetDataSourceException](https://developer.android.com/reference/kotlin/androidx/media3/datasource/AssetDataSource.AssetDataSourceException), [ContentDataSource.ContentDataSourceException](https://developer.android.com/reference/kotlin/androidx/media3/datasource/ContentDataSource.ContentDataSourceException), [FileDataSource.FileDataSourceException](https://developer.android.com/reference/kotlin/androidx/media3/datasource/FileDataSource.FileDataSourceException), [HttpDataSource.HttpDataSourceException](https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource.HttpDataSourceException), [RawResourceDataSource.RawResourceDataSourceException](https://developer.android.com/reference/kotlin/androidx/media3/datasource/RawResourceDataSource.RawResourceDataSourceException), [UdpDataSource.UdpDataSourceException](https://developer.android.com/reference/kotlin/androidx/media3/datasource/UdpDataSource.UdpDataSourceException)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/AssetDataSource.AssetDataSourceException` | Thrown when an `https://developer.android.com/reference/java/io/IOException.html` is encountered reading a local asset. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/ContentDataSource.ContentDataSourceException` | Thrown when an `https://developer.android.com/reference/java/io/IOException.html` is encountered reading from a content URI. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/FileDataSource.FileDataSourceException` | Thrown when a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/FileDataSource` encounters an error reading a file. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource.HttpDataSourceException` | Thrown when an error is encountered when trying to read from a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/RawResourceDataSource.RawResourceDataSourceException` | Thrown when an `https://developer.android.com/reference/java/io/IOException.html` is encountered reading from a raw resource. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/UdpDataSource.UdpDataSourceException` | Thrown when an error is encountered when trying to read from a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/UdpDataSource`. |

Known indirect subclasses [CronetDataSource.OpenException](https://developer.android.com/reference/kotlin/androidx/media3/datasource/cronet/CronetDataSource.OpenException), [HttpDataSource.CleartextNotPermittedException](https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource.CleartextNotPermittedException), [HttpDataSource.InvalidContentTypeException](https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource.InvalidContentTypeException), [HttpDataSource.InvalidResponseCodeException](https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource.InvalidResponseCodeException), [HttpEngineDataSource.OpenException](https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.OpenException)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/cronet/CronetDataSource.OpenException` | Thrown when an error is encountered when trying to open a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/cronet/CronetDataSource`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource.CleartextNotPermittedException` | Thrown when cleartext HTTP traffic is not permitted. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource.InvalidContentTypeException` | Thrown when the content type is invalid. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpDataSource.InvalidResponseCodeException` | Thrown when an attempt to open a connection results in a response code not in the 2xx range. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource.OpenException` | Thrown when an error is encountered when trying to open a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/HttpEngineDataSource`. |

*** ** * ** ***

Used to specify reason of a DataSource error.

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceException#POSITION_OUT_OF_RANGE() = 2008` **This property is deprecated.** Use `https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException#ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE()`. <br /> |

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceException#DataSourceException(int)(@https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode reason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Constructs a DataSourceException. |
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceException#DataSourceException(java.lang.Throwable,int)( cause: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html?, @https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode reason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Constructs a DataSourceException. |
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceException#DataSourceException(java.lang.String,int)( message: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, @https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode reason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Constructs a DataSourceException. |
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceException#DataSourceException(java.lang.String,java.lang.Throwable,int)( message: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, cause: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html?, @https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode reason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Constructs a DataSourceException. |

| ### Public functions |
|---|---|
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceException#isCausedByPositionOutOfRange(java.io.IOException)(e: https://developer.android.com/reference/java/io/IOException.html!)` Returns whether the given `https://developer.android.com/reference/java/io/IOException.html` was caused by a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceException` whose `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceException#reason()` is `https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException#ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE()` in its cause stack. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `@https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceException#reason()` The reason of this `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceException`, should be one of the `ERROR_CODE_IO_*` in `https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode`. |

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

## Constants

### POSITION_OUT_OF_RANGE

```
@UnstableApi
const val POSITION_OUT_OF_RANGE = 2008: Int
```

> [!CAUTION]
> **This property is deprecated.**   
>
> Use `https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException#ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE()`.

Indicates that the `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec#position()` of the request was outside the bounds of the data.

## Public constructors

### DataSourceException

```
@UnstableApi
DataSourceException(@PlaybackException.ErrorCode reason: Int)
```

Constructs a DataSourceException.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode reason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Reason of the error, should be one of the `ERROR_CODE_IO_*` in `https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode`. |

### DataSourceException

```
@UnstableApi
DataSourceException(
    cause: Throwable?,
    @PlaybackException.ErrorCode reason: Int
)
```

Constructs a DataSourceException.

| Parameters |
|---|---|
| `cause: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html?` | The error cause. |
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode reason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Reason of the error, should be one of the `ERROR_CODE_IO_*` in `https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode`. |

### DataSourceException

```
@UnstableApi
DataSourceException(
    message: String?,
    @PlaybackException.ErrorCode reason: Int
)
```

Constructs a DataSourceException.

| Parameters |
|---|---|
| `message: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The error message. |
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode reason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Reason of the error, should be one of the `ERROR_CODE_IO_*` in `https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode`. |

### DataSourceException

```
@UnstableApi
DataSourceException(
    message: String?,
    cause: Throwable?,
    @PlaybackException.ErrorCode reason: Int
)
```

Constructs a DataSourceException.

| Parameters |
|---|---|
| `message: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The error message. |
| `cause: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html?` | The error cause. |
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode reason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Reason of the error, should be one of the `ERROR_CODE_IO_*` in `https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode`. |

## Public functions

### isCausedByPositionOutOfRange

```
@UnstableApi
java-static fun isCausedByPositionOutOfRange(e: IOException!): Boolean
```

Returns whether the given `https://developer.android.com/reference/java/io/IOException.html` was caused by a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceException` whose `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceException#reason()` is `https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException#ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE()` in its cause stack.

## Public properties

### reason

```
@PlaybackException.ErrorCode
val reason: Int
```

The reason of this `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSourceException`, should be one of the `ERROR_CODE_IO_*` in `https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode`.