2 // Tizen Web Device API
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 #include "PlatformException.h"
21 #include "JSWebAPIError.h"
22 #include <CommonsJavaScript/Converter.h>
24 using namespace WrtDeviceApis::CommonsJavaScript;
25 using namespace WrtDeviceApis::Commons;
32 BasePlatformException::BasePlatformException(int code, const char* name, const char* message):mCode(code),mName(name),mMessage(message){
35 BasePlatformException::BasePlatformException(JSContextRef context, JSValueRef value){
36 JSObjectRef object = JSValueToObject(context, value, NULL);
40 JSValueRef message = JSUtil::getProperty(context, object, "message");
41 JSValueRef code = JSUtil::getProperty(context, object, "code");
42 JSValueRef name = JSUtil::getProperty(context, object, "name");
45 Converter convert(context);
46 if( !JSValueIsUndefined(context, message ))
47 mMessage = convert.toString(message);
48 if( !JSValueIsUndefined(context, name ))
49 mName = convert.toString(name);
50 if( !JSValueIsUndefined(context, code ))
51 mCode = convert.toInt(code);
52 }catch( const ConversionException& err){
56 int BasePlatformException::getCode() const{
60 std::string BasePlatformException::getName() const{
64 std::string BasePlatformException::getMessage() const{
69 TypeMismatchException::TypeMismatchException(const char* message):BasePlatformException(JSWebAPIError::TYPE_MISMATCH_ERR,"TypeMismatchError", message){
71 TypeMismatchException::TypeMismatchException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
72 mCode = JSWebAPIError::TYPE_MISMATCH_ERR;
73 mName = "TypeMismatchError";
76 InvalidValuesException::InvalidValuesException(const char* message):BasePlatformException(0,"InvalidValuesError", message){
78 InvalidValuesException::InvalidValuesException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
80 mName = "InvalidValuesError";
83 IOException::IOException(const char* message):BasePlatformException(0,"IOError", message){
85 IOException::IOException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
91 UnknownException::UnknownException(const char* message):BasePlatformException(0,"UnknownError", message){
93 UnknownException::UnknownException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
95 mName = "UnknownError";
98 ServiceNotAvailableException::ServiceNotAvailableException(const char* message):BasePlatformException(0,"ServiceNotAvailableError", message){
100 ServiceNotAvailableException::ServiceNotAvailableException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
102 mName = "ServiceNotAvailableError";
105 SecurityException::SecurityException(const char* message):BasePlatformException(JSWebAPIError::SECURITY_ERR,"SecurityError", message){
107 SecurityException::SecurityException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
108 mCode = JSWebAPIError::SECURITY_ERR;
109 mName = "SecurityError";
112 NotSupportedException::NotSupportedException(const char* message):BasePlatformException(JSWebAPIError::NOT_SUPPORTED_ERR,"NotSupportedError", message){
114 NotSupportedException::NotSupportedException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
115 mCode = JSWebAPIError::NOT_SUPPORTED_ERR;
116 mName = "NotSupportedError";
119 NotFoundException::NotFoundException(const char* message):BasePlatformException(JSWebAPIError::NOT_FOUND_ERR,"NotFoundError", message){
121 NotFoundException::NotFoundException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){
122 mCode = JSWebAPIError::NOT_FOUND_ERR;
123 mName = "NotFoundError";