Error Handling
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, wearable, and TV applications), or return errors in the error event handlers of asynchronous methods with theWebAPIError
interface (in mobile, wearable, and TV 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. -
Generic event handling
You can handle the results of asynchronous operations with generic events. The operations can implemented using the
SuccessCallback
(in mobile, wearable, and TV applications) andErrorCallback
(in mobile, wearable, and TV 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, wearable, and TV 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, wearable, and TV applications).function onSuccess() { console.log('Application terminated successfully'); } tizen.application.kill(ctxIDToKill, onSuccess);
-
The generic
onError()
event handler of theErrorCallBack
interface (in mobile, wearable, and TV 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 and wearable applications).function errorCallback(error) { console.log('The following error occurred: ' + error.name); } tizen.calendar.getCalendars('EVENT', calendarListCallback, errorCallback);
Related Information
- Dependencies
- Tizen 2.4 and Higher for Mobile
- Tizen 2.3.1 and Higher for Wearable
- Tizen 3.0 and Higher for TV