Error Handling
PUBLISHED
You can handle generic error situations in your application.
The Tizen API is mandatory for Tizen mobile, wearable, and TV profiles, which means that it is supported on all mobile, wearable, and TV devices. All mandatory APIs are supported on the Tizen Emulators.
The main error handling features of the Tizen API include:
- Exception handling
You can enable the Tizen APIs to throw errors synchronously with the
WebAPIException
interface (in mobile [1], wearable [2], and TV [3] applications), or return errors in the error event handlers of asynchronous methods with theWebAPIError
interface (in mobile [4], wearable [5], and TV [6] applications).Note Do not use thecode
attribute of theWebAPIException
interface to distinguish errors, because the code of the exception object is set to0
for new error types that are not defined in DOMException [7]. - Generic event handling
You can handle the results of asynchronous operations with generic events. The operations can implemented using the
SuccessCallback
(in mobile [8], wearable [9], and TV [10] applications) andErrorCallback
(in mobile [11], wearable [12], and TV [13] applications) event handlers of the Tizen API.
Using the Generic Event Handlers
Learning how to use generic, predefined event handlers allows you handle application operations and errors efficiently:
-
The generic
onSuccess()
event handler of theSuccessCallBack
interface (in mobile [8], wearable [9], and TV [10] applications) can be used with methods that do not require a return value when successful.In this example, the event handler is used to stop a running application with the
kill()
method of theApplication
interface (in mobile [14], wearable [15], and TV [16] applications).function onSuccess() { console.log('Application terminated successfully'); } tizen.application.kill(ctxIDToKill, onSuccess);
-
The generic
onError()
event handler of theErrorCallBack
interface (in mobile [11], wearable [12], and TV [13] applications) can be used with methods that only require an error as an input parameter in the error callback.In this example, the event handler is used to handle possible errors with the
getCalendars()
method of theCalendarManager
interface (in mobile [17] and wearable [18] applications).function errorCallback(error) { console.log('The following error occurred: ' + error.name); } tizen.calendar.getCalendars('EVENT', calendarListCallback, errorCallback);