StarXpand SDK for iOS/Android Developer's Manual Ver. 1.14.0

Last update: Sep. 15, 2026

Handle Errors

The procedure and the reference vary depending on the OS. Select the OS to display.

iOS Android


This section describes the structures of StarPRNT SDK and StarXpand SDK for error handling operations.

Understand the differences between these SDKs before migrating to StarXpand SDK.


StarPRNT SDK

An NSError-type error is thrown by each API. A value indicating the error kind is stored in NSError.code.
As shown below, an error is treated as an NSError when it is caught, and the error kind is identified by referencing the code property.

import StarIO
import StarIO_Extension

do {
    // Omitted

    var printerStatus = StarPrinterStatus_2()
    try port.beginCheckedBlock(starPrinterStatus: &printerStatus, level: 2)
    
    // Omitted
} catch let error as NSError {
    code = error.code
}



StarXpand SDK

All errors are defined in the StarIO10Error enumeration. When an error occurs in an API, the corresponding error is thrown.
The error kind is identified by checking the StarIO10Error enumerator and its errorCode.

When catching an error, retrieve the message and errorCode as shown below.
This information can be used to identify the specific error kind.

import StarIO10

do {
    try manager?.startDiscovery()
} catch StarIO10Error.illegalDeviceState(message: let message, errorCode: let errorCode) {
    switch errorCode {
    case StarIO10ErrorCode.bluetoothUnavailable: 
        // Bluetooth Unavailable
    case StarIO10ErrorCode.networkUnavailable: 
        // Network Unavailable
    default: 
        break
    } 
} catch {
    print("Error: \(error)")
}



Comparison between the two SDKs

       
StarPRNT SDK StarXpand SDK
Error typeNSError StarIO10Error
Error kind and identification methodcode message and errorCode

Refer to Supported API List for information on whether each API is supported in StarPRNT SDK and StarXpand SDK.

This section describes the structures of StarPRNT SDK and StarXpand SDK for error handling operations.

Understand the differences between these SDKs before migrating to StarXpand SDK.


StarPRNT SDK

A StarIOPortException-type exception is thrown by each API. A value indicating the error kind is stored in StarIOPortException.errorCode.
As shown below, the error kind is identified by referencing the errorCode property of the error when it is caught.

import com.starmicronics.stario.StarIOPort
import com.starmicronics.stario.StarIOPortException

try {
    // Omitted

    val status = StarPrinterStatus()
    port.beginCheckedBlock(status, 2)

    // Omitted
} catch (e: StarIOPortException) {
    val code = e.errorCode
}



StarXpand SDK

All errors are defined as StarIO10Exception subclasses. When an error occurs in an API, the corresponding exception is thrown.
The error kind is identified by checking the StarIO10Exception subclass and its errorCode.

When catching an error, retrieve the message and errorCode as shown below.
This information can be used to identify the specific error kind.

import com.starmicronics.stario10.StarIO10IllegalDeviceStateException
import com.starmicronics.stario10.StarIO10ErrorCode

try {
    manager.startDiscovery()
} catch (e: StarIO10IllegalDeviceStateException) {
    when (e.errorCode) {
        StarIO10ErrorCode.BluetoothUnavailable -> {
            // Bluetooth Unavailable
        }
        StarIO10ErrorCode.NetworkUnavailable -> {
            // Network Unavailable
        }
        else -> {}
    }
} catch (e: Exception) {
    Log.e(TAG, "Error: ${e.message}")
}



Comparison between the two SDKs

       
StarPRNT SDK StarXpand SDK
Error typeStarIOPortException StarIO10Exception (subclass)
Error kind and identification methoderrorCode Subclass type and errorCode

Refer to Supported API List for information on whether each API is supported in StarPRNT SDK and StarXpand SDK.