Last active
May 14, 2022 14:12
-
-
Save enginebai/7e375f7c09b66fa5f4a08071b6540b4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Try not to do this! | |
try { | |
val response = api.fetchUser(userId) | |
} catch (exception) { | |
// skip the error | |
} | |
try { | |
val response = api.fetchUser(userId) | |
} catch (e) { | |
// Log error | |
logger.error(e) | |
when (e) { | |
// Display error message to the users | |
is ApiException -> displayErrorMessage(e.message) | |
is NetworkFailureException -> displayNetworkError() | |
} | |
} | |
// Or provide default/fallback value | |
val count = try { | |
api.fetchProductCount() | |
} catch (exception) { | |
0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment