Build: Error Handling Demo
This screen demonstrates common error handling patterns in Kotlin for Android. It shows how to handle errors from a simulated network call and display messages to the user.
Target UI
------------------------- | Error Handling Demo | |-----------------------| | [Fetch Data] | | | | Status: | | | | Message: | -------------------------
Add a button labeled 'Fetch Data' that triggers a simulated network call.
Simulate success or failure randomly when fetching data.
Use try-catch to handle exceptions from the simulated call.
Display 'Status: Success' or 'Status: Error' accordingly.
Show the error message if an error occurs.
Use Kotlin's runCatching or Result type to demonstrate another error handling pattern.
Ensure UI updates happen on the main thread.