Index: src/libchcore/TCoreStdException.cpp =================================================================== diff -u --- src/libchcore/TCoreStdException.cpp (revision 0) +++ src/libchcore/TCoreStdException.cpp (revision 8aaaa0a6febeeeb6dc7d93b859b58488c54ba5e6) @@ -0,0 +1,39 @@ +// ============================================================================ +// Copyright (C) 2001-2015 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +#include "stdafx.h" +#include "TCoreStdException.h" + +namespace chcore +{ + // ============================================================================ + /// TCoreException::TCoreException + /// @date 2009/11/30 + /// + /// @brief Constructs core exception object with additional data. + /// @param[in] eErrorCode - error code + /// @param[in] stdException - standard exception info + /// @param[in] pszFile - source file name + /// @param[in] stLineNumber - source line number + /// @param[in] pszFunction - function name in which the problem occurred. + // ============================================================================ + TCoreStdException::TCoreStdException(EGeneralErrors eErrorCode, std::exception& stdException, const tchar_t* pszFile, size_t stLineNumber, const tchar_t* pszFunction) : + TCoreException(eErrorCode, stdException.what(), pszFile, stLineNumber, pszFunction) + { + } +} Index: src/libchcore/TCoreStdException.h =================================================================== diff -u --- src/libchcore/TCoreStdException.h (revision 0) +++ src/libchcore/TCoreStdException.h (revision 8aaaa0a6febeeeb6dc7d93b859b58488c54ba5e6) @@ -0,0 +1,37 @@ +// ============================================================================ +// Copyright (C) 2001-2015 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +#ifndef __TCORESTDEXCEPTION_H__ +#define __TCORESTDEXCEPTION_H__ + +#include "libchcore.h" +#include "TCoreException.h" + +#define THROW_CORE_EXCEPTION_STD(error_code, std_exception)\ + throw chcore::TCoreStdException(error_code, std_exception, __FILEW__, __LINE__, __FUNCTIONW__) + +namespace chcore +{ + class LIBCHCORE_API TCoreStdException : public TCoreException + { + public: + TCoreStdException(EGeneralErrors eErrorCode, std::exception& stdException, const tchar_t* pszFile, size_t stLineNumber, const tchar_t* pszFunction); + }; +} + +#endif Index: src/libchcore/TCoreWin32Exception.cpp =================================================================== diff -u --- src/libchcore/TCoreWin32Exception.cpp (revision 0) +++ src/libchcore/TCoreWin32Exception.cpp (revision 8aaaa0a6febeeeb6dc7d93b859b58488c54ba5e6) @@ -0,0 +1,60 @@ +// ============================================================================ +// Copyright (C) 2001-2015 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +#include "stdafx.h" +#include "TCoreWin32Exception.h" + +namespace chcore +{ + // ============================================================================ + /// TCoreWin32Exception::TCoreWin32Exception + /// @date 2011/07/18 + /// + /// @brief Constructs core win32 exception. + /// @param[in] eErrorCode - core error code + /// @param[in] dwWin32Exception - win32 error code + /// @param[in] pszFile -source file where the exception was thrown + /// @param[in] stLineNumber - source code line number where the exception was thrown + /// @param[in] pszFunction - function throwing the exception + // ============================================================================ + TCoreWin32Exception::TCoreWin32Exception(EGeneralErrors eErrorCode, DWORD dwWin32Exception, const wchar_t* pszMsg, const wchar_t* pszFile, size_t stLineNumber, const wchar_t* pszFunction) : + TCoreException(eErrorCode, pszMsg, pszFile, stLineNumber, pszFunction), + m_dwWin32ErrorCode(dwWin32Exception) + { + } + + // ============================================================================ + /// TCoreWin32Exception::GetErrorInfo + /// @date 2011/07/18 + /// + /// @brief Retrieves formatted exception information. + /// @param[in] pszBuffer - buffer for formatted string + /// @param[in] stMaxBuffer - max size of buffer + // ============================================================================ + void TCoreWin32Exception::GetErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const + { + _snwprintf_s(pszBuffer, stMaxBuffer, _TRUNCATE, _T("%s (error code: %ld, win32 error code: %lu)"), m_pszMsg, m_eErrorCode, m_dwWin32ErrorCode); + pszBuffer[stMaxBuffer - 1] = _T('\0'); + } + + void TCoreWin32Exception::GetDetailedErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const + { + _snwprintf_s(pszBuffer, stMaxBuffer, _TRUNCATE, _T("%s\r\nError code: %ld\r\nWin32 error code: %lu\r\nFile: %s\r\nFunction: %s\r\nLine no: %lu"), m_pszMsg, m_eErrorCode, m_dwWin32ErrorCode, m_pszFile, m_pszFunction, (unsigned long)m_stLineNumber); + pszBuffer[stMaxBuffer - 1] = _T('\0'); + } +} Index: src/libchcore/TCoreWin32Exception.h =================================================================== diff -u --- src/libchcore/TCoreWin32Exception.h (revision 0) +++ src/libchcore/TCoreWin32Exception.h (revision 8aaaa0a6febeeeb6dc7d93b859b58488c54ba5e6) @@ -0,0 +1,47 @@ +// ============================================================================ +// Copyright (C) 2001-2015 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +#ifndef __TCOREWIN32EXCEPTION_H__ +#define __TCOREWIN32EXCEPTION_H__ + +#include "TCoreException.h" + +#define THROW_CORE_EXCEPTION_WIN32(error_code, win32_error_code)\ + throw chcore::TCoreWin32Exception(error_code, win32_error_code, L"", __FILEW__, __LINE__, __FUNCTIONW__) + +#define THROW_CORE_EXCEPTION_WIN32_MSG(error_code, win32_error_code, msg)\ + throw chcore::TCoreWin32Exception(error_code, win32_error_code, msg, __FILEW__, __LINE__, __FUNCTIONW__) + +namespace chcore +{ + class LIBCHCORE_API TCoreWin32Exception : public TCoreException + { + public: + TCoreWin32Exception(EGeneralErrors eErrorCode, DWORD dwWin32Exception, const wchar_t* pszMsg, const wchar_t* pszFile, size_t stLineNumber, const wchar_t* pszFunction); + + DWORD GetWin32ErrorCode() const { return m_dwWin32ErrorCode; } + + virtual void GetErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const; + virtual void GetDetailedErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const; + + protected: + DWORD m_dwWin32ErrorCode; + }; +} + +#endif Index: src/libchcore/TFileException.cpp =================================================================== diff -u --- src/libchcore/TFileException.cpp (revision 0) +++ src/libchcore/TFileException.cpp (revision 8aaaa0a6febeeeb6dc7d93b859b58488c54ba5e6) @@ -0,0 +1,43 @@ +// ============================================================================ +// Copyright (C) 2001-2015 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +#include "stdafx.h" +#include "TFileException.h" + +namespace chcore +{ + TFileException::TFileException(EGeneralErrors eErrorCode, DWORD dwNativeErrorCode, const TSmartPath& path, wchar_t* pszMsg, const wchar_t* pszFile, size_t stLineNumber, const wchar_t* pszFunction) : + TCoreException(eErrorCode, pszMsg, pszFile, stLineNumber, pszFunction), + m_path(path), + m_dwNativeErrorCode(dwNativeErrorCode) + { + } + + void TFileException::GetErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const + { + _snwprintf_s(pszBuffer, stMaxBuffer, _TRUNCATE, _T("%s (error code: %ld, win32 error code: %lu, path: %s)"), m_pszMsg, m_eErrorCode, m_dwNativeErrorCode, m_path.ToString()); + pszBuffer[stMaxBuffer - 1] = _T('\0'); + } + + void TFileException::GetDetailedErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const + { + _snwprintf_s(pszBuffer, stMaxBuffer, _TRUNCATE, _T("%s\r\nError code: %ld\r\nWin32 error code: %lu\r\nFile: %s\r\nSource file: %s\r\nFunction: %s\r\nLine no: %lu"), + m_pszMsg, m_eErrorCode, m_dwNativeErrorCode, m_path.ToString(), m_pszFile, m_pszFunction, (unsigned long)m_stLineNumber); + pszBuffer[stMaxBuffer - 1] = _T('\0'); + } +} Index: src/libchcore/TFileException.h =================================================================== diff -u --- src/libchcore/TFileException.h (revision 0) +++ src/libchcore/TFileException.h (revision 8aaaa0a6febeeeb6dc7d93b859b58488c54ba5e6) @@ -0,0 +1,50 @@ +// ============================================================================ +// Copyright (C) 2001-2015 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +#ifndef __TFILEWIN32EXCEPTION_H__ +#define __TFILEWIN32EXCEPTION_H__ + +#include "libchcore.h" +#include "ErrorCodes.h" +#include "TPath.h" +#include "TCoreException.h" + +#define THROW_FILE_EXCEPTION(error_code, native_error_code, path, msg)\ + throw chcore::TFileException(error_code, native_error_code, path, msg, __FILEW__, __LINE__, __FUNCTIONW__) + +namespace chcore +{ + class LIBCHCORE_API TFileException : public TCoreException + { + public: + TFileException(EGeneralErrors eErrorCode, DWORD dwNativeErrorCode, const TSmartPath& path, wchar_t* pszMsg, + const wchar_t* pszFile, size_t stLineNumber, const wchar_t* pszFunction); + + virtual void GetErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const; + virtual void GetDetailedErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const; + + const TSmartPath& GetPath() const { return m_path; } + DWORD GetNativeError() const { return m_dwNativeErrorCode; } + + private: + DWORD m_dwNativeErrorCode; + TSmartPath m_path; + }; +} + +#endif