# 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)

*** ** * ** ***


```
public class DataSourceException extends IOException
```

<br />

|---|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||||
| ↳ | [kotlin.Throwable](https://developer.android.com/reference/java/lang/Throwable.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/androidx/media3/datasource/DataSourceException) |

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

|---|---|
| `https://developer.android.com/reference/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/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/androidx/media3/datasource/FileDataSource.FileDataSourceException` | Thrown when a `https://developer.android.com/reference/androidx/media3/datasource/FileDataSource` encounters an error reading a file. |
| `https://developer.android.com/reference/androidx/media3/datasource/HttpDataSource.HttpDataSourceException` | Thrown when an error is encountered when trying to read from a `https://developer.android.com/reference/androidx/media3/datasource/HttpDataSource`. |
| `https://developer.android.com/reference/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/androidx/media3/datasource/UdpDataSource.UdpDataSourceException` | Thrown when an error is encountered when trying to read from a `https://developer.android.com/reference/androidx/media3/datasource/UdpDataSource`. |

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

|---|---|
| `https://developer.android.com/reference/androidx/media3/datasource/cronet/CronetDataSource.OpenException` | Thrown when an error is encountered when trying to open a `https://developer.android.com/reference/androidx/media3/datasource/cronet/CronetDataSource`. |
| `https://developer.android.com/reference/androidx/media3/datasource/HttpDataSource.CleartextNotPermittedException` | Thrown when cleartext HTTP traffic is not permitted. |
| `https://developer.android.com/reference/androidx/media3/datasource/HttpDataSource.InvalidContentTypeException` | Thrown when the content type is invalid. |
| `https://developer.android.com/reference/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/androidx/media3/datasource/HttpEngineDataSource.OpenException` | Thrown when an error is encountered when trying to open a `https://developer.android.com/reference/androidx/media3/datasource/HttpEngineDataSource`. |

*** ** * ** ***

Used to specify reason of a DataSource error.

## Summary

| ### Constants |
|---|---|
| `static final int` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/datasource/DataSourceException#POSITION_OUT_OF_RANGE() = 2008` **This field is deprecated.** Use `https://developer.android.com/reference/androidx/media3/common/PlaybackException#ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE()`. <br /> |

| ### Public fields |
|---|---|
| `final int` | `@https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode https://developer.android.com/reference/androidx/media3/datasource/DataSourceException#reason()` The reason of this `https://developer.android.com/reference/androidx/media3/datasource/DataSourceException`, should be one of the `ERROR_CODE_IO_*` in `https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode`. |

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/datasource/DataSourceException#DataSourceException(int)(@https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode int reason)` Constructs a DataSourceException. |
| `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/datasource/DataSourceException#DataSourceException(java.lang.Throwable,int)( @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Throwable.html cause, @https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode int reason )` Constructs a DataSourceException. |
| `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/datasource/DataSourceException#DataSourceException(java.lang.String,int)( @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html message, @https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode int reason )` Constructs a DataSourceException. |
| `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/datasource/DataSourceException#DataSourceException(java.lang.String,java.lang.Throwable,int)( @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html message, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Throwable.html cause, @https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode int reason )` Constructs a DataSourceException. |

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

### 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 exception)` `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 cause)` `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[] stackTrace)` `https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/java/lang/Throwable.html#toString()()`

## Constants

### POSITION_OUT_OF_RANGE

```
@UnstableApi
public static final int POSITION_OUT_OF_RANGE = 2008
```

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

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

## Public fields

### reason

```
@PlaybackException.ErrorCode
public final int reason
```

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

## Public constructors

### DataSourceException

```
@UnstableApi
public DataSourceException(@PlaybackException.ErrorCode int reason)
```

Constructs a DataSourceException.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode int reason` | Reason of the error, should be one of the `ERROR_CODE_IO_*` in `https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode`. |

### DataSourceException

```
@UnstableApi
public DataSourceException(
    @Nullable Throwable cause,
    @PlaybackException.ErrorCode int reason
)
```

Constructs a DataSourceException.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Throwable.html cause` | The error cause. |
| `@https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode int reason` | Reason of the error, should be one of the `ERROR_CODE_IO_*` in `https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode`. |

### DataSourceException

```
@UnstableApi
public DataSourceException(
    @Nullable String message,
    @PlaybackException.ErrorCode int reason
)
```

Constructs a DataSourceException.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html message` | The error message. |
| `@https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode int reason` | Reason of the error, should be one of the `ERROR_CODE_IO_*` in `https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode`. |

### DataSourceException

```
@UnstableApi
public DataSourceException(
    @Nullable String message,
    @Nullable Throwable cause,
    @PlaybackException.ErrorCode int reason
)
```

Constructs a DataSourceException.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html message` | The error message. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Throwable.html cause` | The error cause. |
| `@https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode int reason` | Reason of the error, should be one of the `ERROR_CODE_IO_*` in `https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode`. |

## Public methods

### isCausedByPositionOutOfRange

```
@UnstableApi
public static boolean isCausedByPositionOutOfRange(IOException e)
```

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