The Kotlin SDK uses a hierarchy of exceptions to help developers manage API call failures. There are two major categories of exceptions that your application should handle when using the Kotlin SDK:
Loserrores de dominio ocurren cuando falla una lectura o escritura en el dominio. Estos errores generan un Excepción de reino.
app errors occur when network communication with Atlas App Services fails. These errors generate an AppException. For more information on app errors, refer to Handle App Errors. For more information on sync-specific app errors, refer to Handle Sync Errors.
Realm Errors
Los errores de dominio ocurren cuando falla la lectura o escritura de una base de datos por cualquier motivo. Siempre que es posible, el SDK utiliza excepciones de plataforma existentes, como IllegalArgumentException.o IllegalStateException.
Typically, these errors result from bad database logic, such as a query missing an argument, attempting to write outside of a write transaction, or deleting an object that does not exist.
However, some errors are ephemeral: they occur because of failures outside of the client or SDK's control. When an ephemeral error occurs, you should retry the operation that caused the error. If the operation still fails when you retry it, investigate logic fixes.
Puedes gestionar errores en el SDK con la API runCatching integrada de Kotlin. Usa el onSuccess y onFailure devoluciones de llamadas del resultado devuelto para manejar llamadas exitosas a la API del SDK y casos de error.