• Start

Languages

/

Kotlin

/

API Reference

/

Errors

Errors

The exception hierarchy raised by the SurrealDB Kotlin SDK.

The Kotlin SDK raises exceptions that all extend the sealed base class SurrealException. Because the hierarchy is sealed, you can branch over it exhaustively with when. See Error handling for usage patterns and the Result variants that avoid exceptions altogether.

Source: surrealdb.kotlin

Import

import com.surrealdb.kotlin.error.SurrealException

The sealed base class of all SDK exceptions. Extends RuntimeException.

Raised when the underlying connection fails, drops, or cannot be established.

Raised when a malformed or unexpected message is received from the server.

Raised when the server returns an RPC error.

PropertyTypeDescription
codeInt?The RPC error code.
dataJsonElement?Additional error data from the server.

A subclass of SurrealRpcException raised when authentication fails (for example, invalid credentials or an expired token).

Raised when a feature is invoked that the current transport does not support — for example a live query or transaction over HTTP. Extends the base SurrealException. Guard against it with .supports().

Example

import com.surrealdb.kotlin.error.SurrealAuthenticationException
import com.surrealdb.kotlin.error.SurrealException

try {
client.signin(buildJsonObject { put("user", "root"); put("pass", "wrong") })
} catch (e: SurrealAuthenticationException) {
println("authentication failed: ${e.message}")
} catch (e: SurrealException) {
println("error: ${e.message}")
}

Was this page helpful?