# MediaDrm.SessionException

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# SessionException

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/media/MediaDrm.SessionException "View this page in Java")  

```
class SessionException : RuntimeException, MediaDrmThrowable
```

|---|---|---|---|------------------------------------------------------------------------------------------------------------------------------------|
| [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/kotlin/java/lang/Exception.html#)                                          |||
|   |   | ↳ | [java.lang.RuntimeException](https://developer.android.com/reference/kotlin/java/lang/RuntimeException.html#)                         ||
|   |   |   | ↳ | [android.media.MediaDrm.SessionException](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#) |

[SessionException](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#)is a misnomer because it may occur in methods**without**a session context.

A[SessionException](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#)is most likely to be thrown when an operation failed in a way that is likely to succeed on a subsequent attempt; call[isTransient()](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#isTransient())to determine whether the app should retry the failing operation.

## Summary

|                                                                                                                                                                             Constants                                                                                                                                                                             ||
|----------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [ERROR_RESOURCE_CONTENTION](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#ERROR_RESOURCE_CONTENTION:kotlin.Int) This indicates that apps using MediaDrm sessions are temporarily exceeding the capacity of available crypto resources. |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [ERROR_UNKNOWN](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#ERROR_UNKNOWN:kotlin.Int) The SessionException has an unknown error code.                                                                                                |

|                                                                                                                                                                          Public constructors                                                                                                                                                                          ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [SessionException](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#SessionException(kotlin.Int,%20kotlin.String))`(`errorCode:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `detailMessage:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?`)` <br /> |

|                                                                                                                                                                                                                                              Public methods                                                                                                                                                                                                                                               ||
|------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)         | [getErrorCode](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#getErrorCode())`()` Retrieve the error code associated with the SessionException                                                                                                                                                                                                                                |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)         | [getErrorContext](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#getErrorContext())`()` <br />                                                                                                                                                                                                                                                                                |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)         | [getOemError](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#getOemError())`()` <br />                                                                                                                                                                                                                                                                                        |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)         | [getVendorError](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#getVendorError())`()` <br />                                                                                                                                                                                                                                                                                  |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [isTransient](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#isTransient())`()` Returns true if the[SessionException](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#)is a transient issue, perhaps due to resource constraints, and that the operation (e.g. provisioning, generating requests) may succeed on a subsequent attempt. |

## Constants

### ERROR_RESOURCE_CONTENTION

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val ERROR_RESOURCE_CONTENTION: Int
```

**Deprecated:** *Please use[isTransient()](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#isTransient())instead of comparing the return value of[getErrorCode()](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#getErrorCode())against[SessionException.ERROR_RESOURCE_CONTENTION](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#ERROR_RESOURCE_CONTENTION:kotlin.Int).*

This indicates that apps using MediaDrm sessions are temporarily exceeding the capacity of available crypto resources. The app should retry the operation later.  

    Value: 1

### ERROR_UNKNOWN

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val ERROR_UNKNOWN: Int
```

**Deprecated:** *Unused.*

The SessionException has an unknown error code.  

    Value: 0

## Public constructors

### SessionException

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
SessionException(
    errorCode: Int, 
    detailMessage: String?)
```

|                                                         Parameters                                                          ||
|-----------------|------------------------------------------------------------------------------------------------------------|
| `detailMessage` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?:This value may be`null`. |

## Public methods

### getErrorCode

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

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

**Deprecated:** *Please use[isTransient()](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#isTransient())instead of comparing the return value of[getErrorCode()](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#getErrorCode())against[SessionException.ERROR_RESOURCE_CONTENTION](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#ERROR_RESOURCE_CONTENTION:kotlin.Int).*

Retrieve the error code associated with the SessionException

|                                                                                                                                        Return                                                                                                                                        ||
|----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | Value is[android.media.MediaDrm.SessionException#ERROR_RESOURCE_CONTENTION](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#ERROR_RESOURCE_CONTENTION:kotlin.Int) |

### getErrorContext

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun getErrorContext(): Int
```

|                                                                                                                                Return                                                                                                                                ||
|----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | an opaque integer that would help the @[MediaDrm](https://developer.android.com/reference/kotlin/android/media/MediaDrm)vendor locate the source of the error if available, otherwise 0. |

### getOemError

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun getOemError(): Int
```

|                                                                  Return                                                                  ||
|----------------------------------------------------------------------------|--------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | an OEM or SOC specific error code if available, otherwise 0. |

### getVendorError

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun getVendorError(): Int
```

|                                                                                                              Return                                                                                                               ||
|----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | an error code defined by the[MediaDrm](https://developer.android.com/reference/kotlin/android/media/MediaDrm)plugin vendor if available, otherwise 0. |

### isTransient

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun isTransient(): Boolean
```

Returns true if the[SessionException](https://developer.android.com/reference/kotlin/android/media/MediaDrm.SessionException#)is a transient issue, perhaps due to resource constraints, and that the operation (e.g. provisioning, generating requests) may succeed on a subsequent attempt.