diff options
Diffstat (limited to 'mobile_src/Common/PlatformException.cpp')
-rw-r--r-- | mobile_src/Common/PlatformException.cpp | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/mobile_src/Common/PlatformException.cpp b/mobile_src/Common/PlatformException.cpp new file mode 100644 index 0000000..168664d --- /dev/null +++ b/mobile_src/Common/PlatformException.cpp @@ -0,0 +1,130 @@ +// +// Tizen Web Device API +// Copyright (c) 2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + + +#include "PlatformException.h" +#include "JSUtil.h" +#include "JSWebAPIErrorFactory.h" +#include <CommonsJavaScript/Converter.h> + +using namespace WrtDeviceApis::CommonsJavaScript; +using namespace WrtDeviceApis::Commons; + + + +namespace DeviceAPI { +namespace Common{ + +BasePlatformException::BasePlatformException(const char* name, const char* message):mName(name),mMessage(message){ +} + +BasePlatformException::BasePlatformException(JSContextRef context, JSValueRef value){ + JSObjectRef object = JSValueToObject(context, value, NULL); + if( object == NULL ) + return; + + JSValueRef message = JSUtil::getProperty(context, object, "message"); + JSValueRef name = JSUtil::getProperty(context, object, "name"); + + try{ + Converter convert(context); + if( !JSValueIsUndefined(context, message )) + mMessage = convert.toString(message); + if( !JSValueIsUndefined(context, name )) + mName = convert.toString(name); + }catch( const ConversionException& err){ + } +} + +BasePlatformException::~BasePlatformException() { +} + +std::string BasePlatformException::getName() const{ + return mName; +} + +std::string BasePlatformException::getMessage() const{ + return mMessage; +} + + +TypeMismatchException::TypeMismatchException(const char* message):BasePlatformException("TypeMismatchError", message){ +} +TypeMismatchException::TypeMismatchException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){ + mName = "TypeMismatchError"; +} + +InvalidValuesException::InvalidValuesException(const char* message):BasePlatformException("InvalidValuesError", message){ +} +InvalidValuesException::InvalidValuesException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){ + mName = "InvalidValuesError"; +} + +IOException::IOException(const char* message):BasePlatformException("IOError", message){ +} +IOException::IOException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){ + mName = "IOError"; +} + + +UnknownException::UnknownException(const char* message):BasePlatformException("UnknownError", message){ +} +UnknownException::UnknownException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){ + mName = "UnknownError"; +} + +ServiceNotAvailableException::ServiceNotAvailableException(const char* message):BasePlatformException("ServiceNotAvailableError", message){ +} +ServiceNotAvailableException::ServiceNotAvailableException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){ + mName = "ServiceNotAvailableError"; +} + +SecurityException::SecurityException(const char* message):BasePlatformException("SecurityError", message){ +} +SecurityException::SecurityException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){ + mName = "SecurityError"; +} + +NotSupportedException::NotSupportedException(const char* message):BasePlatformException("NotSupportedError", message){ +} +NotSupportedException::NotSupportedException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){ + mName = "NotSupportedError"; +} + +NotFoundException::NotFoundException(const char* message):BasePlatformException("NotFoundError", message){ +} +NotFoundException::NotFoundException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){ + mName = "NotFoundError"; +} + +InvalidAccessException::InvalidAccessException(const char* message):BasePlatformException("InvalidAccessError", message){ +} +InvalidAccessException::InvalidAccessException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){ + mName = "InvalidAccessError"; +} + +QuotaExceededException::QuotaExceededException(const char* message):BasePlatformException("QuotaExceededError", message){ +} +QuotaExceededException::QuotaExceededException(JSContextRef ctx, JSValueRef exception):BasePlatformException(ctx,exception){ + mName = "QuotaExceededError"; +} + + + + +} +} |