MqttException

sealed class MqttException : Exception

Base exception for all MQTT client errors.

Every exception thrown by MqttClient extends this type, so consumers can catch MqttException to handle any library error, or match specific subtypes for fine-grained error handling.

Example

try {
client.connect(endpoint)
} catch (e: MqttException.ConnectionRejected) {
println("Broker rejected: ${e.reasonCode}")
} catch (e: MqttException.ProtocolError) {
println("Protocol violation: ${e.message}")
} catch (e: MqttException) {
println("MQTT error: ${e.message}")
}

Inheritors

Types

Link copied to clipboard
class ConnectionLost(reasonCode: ReasonCode, message: String, cause: Throwable? = null) : MqttException

The connection was lost unexpectedly.

Link copied to clipboard
class ConnectionRejected(reasonCode: ReasonCode, message: String, cause: Throwable? = null, val serverReference: String? = null) : MqttException

The broker rejected the CONNECT request (§3.2).

Link copied to clipboard
class ProtocolError(reasonCode: ReasonCode, message: String, cause: Throwable? = null) : MqttException

A protocol-level error occurred.

Properties

Link copied to clipboard
expect open val cause: Throwable?
Link copied to clipboard
expect open val message: String?
Link copied to clipboard

The MQTT 5.0 reason code associated with this error.