Handle Errors
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 type | NSError | StarIO10Error |
| Error kind and identification method | code | message and errorCode |
Refer to Supported API List for information on whether each API is supported in StarPRNT SDK and StarXpand SDK.
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 type | StarIOPortException | StarIO10Exception (subclass) |
| Error kind and identification method | errorCode | Subclass type and errorCode |
Refer to Supported API List for information on whether each API is supported in StarPRNT SDK and StarXpand SDK.

