Handling Errors Better
What are errors? There could be many definitions, but for our discussion here, we want to concentrate on a somewhat narrow meaning: an error occurs when the software doesn’t behave as we expect.
For example, a network call can’t connect, an input parameter isn’t of the expected type, a component isn’t in the right state to perform some work. Our aim is to detect these errors as early as possible and either recover, or failing that, report all the information required to fix the problem back to the client and to the log.
Until now, we have deliberately sidestepped a close examination of errors, but proper error reporting is crucial for maintaining code that’s easy to manage and debug. By utilizing Kotlin’s explicit nullability, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access