javacommons/utils/src/exceptionbase.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 17 Sep 2010 08:28:21 +0300
changeset 76 4ad59aaee882
parent 21 2a9601315dfc
permissions -rw-r--r--
Revision: v2.2.13 Kit: 201037

/*
* Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
*
*/

#include <sstream>
#include "exceptionbase.h"

using namespace java::util;

OS_EXPORT std::string ExceptionBase::toString() const
{
    std::ostringstream extendedMessage;

    extendedMessage << mMessage;

    if (0 != mErrCode)
    {
        extendedMessage << ": error code [" << mErrCode << "], ";
    }

    if (0 != mStatusCode)
    {
        extendedMessage << "status code [" << mStatusCode << "], ";
    }

    extendedMessage << " (file: " << mFile;
    extendedMessage << ", method: " << mMethod;
    extendedMessage << ", line: " << mLine;
    extendedMessage << ").";

    return extendedMessage.str();
}

OS_EXPORT ExceptionBase::ExceptionBase(const ExceptionBase& x) : std::exception(x)
{
    mErrCode    = x.mErrCode;
    mMessage    = x.mMessage;
    mStatusCode = x.mStatusCode;
    mFile       = x.mFile;
    mMethod     = x.mMethod;
    mLine       = x.mLine;
}

OS_EXPORT const char* ExceptionBase::what() const throw()
{
    return toString().c_str();
}

OS_EXPORT ExceptionBase::ExceptionBase(const std::string& message,
                                       const std::string& file,
                                       const std::string& method,
                                       int line) throw() :
        mErrCode(0),
        mStatusCode(0),
        mMessage(message),
        mFile(file),
        mMethod(method),
        mLine(line)
{
}

OS_EXPORT ExceptionBase::ExceptionBase(int aErrCode,
                                       const std::string& message,
                                       const std::string& file,
                                       const std::string& method,
                                       int line) throw() :
        mErrCode(aErrCode),
        mStatusCode(0),
        mMessage(message),
        mFile(file),
        mMethod(method),
        mLine(line)
{
}

OS_EXPORT ExceptionBase::ExceptionBase(int aErrCode,
                                       int aStatusCode,
                                       const std::string& message,
                                       const std::string& file,
                                       const std::string& method,
                                       int line) throw() :
        mErrCode(aErrCode),
        mStatusCode(aStatusCode),
        mMessage(message),
        mFile(file),
        mMethod(method),
        mLine(line)
{
}

OS_EXPORT ExceptionBase::ExceptionBase(const std::wstring& message,
                                       const std::string& file,
                                       const std::string& method,
                                       int line) throw() :
        mErrCode(0),
        mStatusCode(0),
        mFile(file),
        mMethod(method),
        mLine(line)
{
    mMessage.assign(message.begin(),message.end());
}

OS_EXPORT ExceptionBase::ExceptionBase(int aErrCode,
                                       const std::wstring& message,
                                       const std::string& file,
                                       const std::string& method,
                                       int line) throw() :
        mErrCode(aErrCode),
        mStatusCode(0),
        mFile(file),
        mMethod(method),
        mLine(line)
{
    mMessage.assign(message.begin(),message.end());
}

OS_EXPORT ExceptionBase::ExceptionBase(int aErrCode,
                                       int aStatusCode,
                                       const std::wstring& message,
                                       const std::string& file,
                                       const std::string& method,
                                       int line) throw() :
        mErrCode(aErrCode),
        mStatusCode(aStatusCode),
        mFile(file), mMethod(method),
        mLine(line)
{
    mMessage.assign(message.begin(),message.end());
}

OS_EXPORT ExceptionBase::~ExceptionBase() throw()
{

}