In mobile app development, things can go wrong easily. Especially when using the device APIs, Web APIs and network features, there is always a chance for network being down, permission not being granted, etc. Yet, your app should never crash, which means you should handle exceptions gracefully.
There is an enum in Zebble called OnError which defines your preferred reaction in cases of any unhandled exceptions when calling a method. It helps keep your code simple and clean while keeping the user informed when necessary. The options in this enum are:
Several APIs in Zebble support an optional parameter of the type OnError. The following example is to turn on the device torch (lamp) by providing the error handling strategy parameter:
// This means the app will not crash, yet the user will be informed that turning on the lamp failed.
// TODO: Handle it differently
When creating your own reusable components and APIs you might want to support OnError to enhance the usability of your component. The following explains how you can implement it: