javacommons/utils/src/exceptionbase.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <sstream>
       
    19 #include "exceptionbase.h"
       
    20 
       
    21 using namespace java::util;
       
    22 
       
    23 OS_EXPORT std::string ExceptionBase::toString() const
       
    24 {
       
    25     std::ostringstream extendedMessage;
       
    26 
       
    27     extendedMessage << mMessage;
       
    28 
       
    29     if (0 != mErrCode)
       
    30     {
       
    31         extendedMessage << ": error code [" << mErrCode << "], ";
       
    32     }
       
    33 
       
    34     if (0 != mStatusCode)
       
    35     {
       
    36         extendedMessage << "status code [" << mStatusCode << "], ";
       
    37     }
       
    38 
       
    39     extendedMessage << " (file: " << mFile;
       
    40     extendedMessage << ", method: " << mMethod;
       
    41     extendedMessage << ", line: " << mLine;
       
    42     extendedMessage << ").";
       
    43 
       
    44     return extendedMessage.str();
       
    45 }
       
    46 
       
    47 OS_EXPORT ExceptionBase::ExceptionBase(const ExceptionBase& x) : std::exception(x)
       
    48 {
       
    49     mErrCode    = x.mErrCode;
       
    50     mMessage    = x.mMessage;
       
    51     mStatusCode = x.mStatusCode;
       
    52     mFile       = x.mFile;
       
    53     mMethod     = x.mMethod;
       
    54     mLine       = x.mLine;
       
    55 }
       
    56 
       
    57 OS_EXPORT const char* ExceptionBase::what() const throw()
       
    58 {
       
    59     return toString().c_str();
       
    60 }
       
    61 
       
    62 OS_EXPORT ExceptionBase::ExceptionBase(const std::string& message,
       
    63                                        const std::string& file,
       
    64                                        const std::string& method,
       
    65                                        int line) throw() :
       
    66         mErrCode(0),
       
    67         mStatusCode(0),
       
    68         mMessage(message),
       
    69         mFile(file),
       
    70         mMethod(method),
       
    71         mLine(line)
       
    72 {
       
    73 }
       
    74 
       
    75 OS_EXPORT ExceptionBase::ExceptionBase(int aErrCode,
       
    76                                        const std::string& message,
       
    77                                        const std::string& file,
       
    78                                        const std::string& method,
       
    79                                        int line) throw() :
       
    80         mErrCode(aErrCode),
       
    81         mStatusCode(0),
       
    82         mMessage(message),
       
    83         mFile(file),
       
    84         mMethod(method),
       
    85         mLine(line)
       
    86 {
       
    87 }
       
    88 
       
    89 OS_EXPORT ExceptionBase::ExceptionBase(int aErrCode,
       
    90                                        int aStatusCode,
       
    91                                        const std::string& message,
       
    92                                        const std::string& file,
       
    93                                        const std::string& method,
       
    94                                        int line) throw() :
       
    95         mErrCode(aErrCode),
       
    96         mStatusCode(aStatusCode),
       
    97         mMessage(message),
       
    98         mFile(file),
       
    99         mMethod(method),
       
   100         mLine(line)
       
   101 {
       
   102 }
       
   103 
       
   104 OS_EXPORT ExceptionBase::ExceptionBase(const std::wstring& message,
       
   105                                        const std::string& file,
       
   106                                        const std::string& method,
       
   107                                        int line) throw() :
       
   108         mErrCode(0),
       
   109         mStatusCode(0),
       
   110         mFile(file),
       
   111         mMethod(method),
       
   112         mLine(line)
       
   113 {
       
   114     mMessage.assign(message.begin(),message.end());
       
   115 }
       
   116 
       
   117 OS_EXPORT ExceptionBase::ExceptionBase(int aErrCode,
       
   118                                        const std::wstring& message,
       
   119                                        const std::string& file,
       
   120                                        const std::string& method,
       
   121                                        int line) throw() :
       
   122         mErrCode(aErrCode),
       
   123         mStatusCode(0),
       
   124         mFile(file),
       
   125         mMethod(method),
       
   126         mLine(line)
       
   127 {
       
   128     mMessage.assign(message.begin(),message.end());
       
   129 }
       
   130 
       
   131 OS_EXPORT ExceptionBase::ExceptionBase(int aErrCode,
       
   132                                        int aStatusCode,
       
   133                                        const std::wstring& message,
       
   134                                        const std::string& file,
       
   135                                        const std::string& method,
       
   136                                        int line) throw() :
       
   137         mErrCode(aErrCode),
       
   138         mStatusCode(aStatusCode),
       
   139         mFile(file), mMethod(method),
       
   140         mLine(line)
       
   141 {
       
   142     mMessage.assign(message.begin(),message.end());
       
   143 }
       
   144 
       
   145 OS_EXPORT ExceptionBase::~ExceptionBase() throw()
       
   146 {
       
   147 
       
   148 }
       
   149