Improved Error system

Former-commit-id: ddd08841d30575713f4a28ac02566f92791e5539
This commit is contained in:
Lynix
2013-09-25 09:29:25 +02:00
parent 672cbaed1d
commit a410e8856a
16 changed files with 199 additions and 51 deletions

View File

@@ -25,6 +25,18 @@ enum nzEndianness
nzEndianness_Max = nzEndianness_LittleEndian
};
enum nzErrorFlag
{
nzErrorFlag_None = 0,
nzErrorFlag_Silent = 0x1,
nzErrorFlag_SilentDisabled = 0x2,
nzErrorFlag_ThrowException = 0x4,
nzErrorFlag_ThrowExceptionDisabled = 0x8,
nzErrorFlag_Max = nzErrorFlag_ThrowExceptionDisabled*2-1
};
enum nzErrorType
{
nzErrorType_AssertFailed,
@@ -113,7 +125,7 @@ enum nzSphereType
enum nzStreamOptionFlags
{
nzStreamOption_None = 0x0,
nzStreamOption_None = 0,
nzStreamOption_Text = 0x1,

View File

@@ -14,17 +14,37 @@
#include <Nazara/Core/String.hpp>
#if NAZARA_CORE_ENABLE_ASSERTS || defined(NAZARA_DEBUG)
#define NazaraAssert(a, err) if (!(a)) NzError(nzErrorType_AssertFailed, err, __LINE__, NzDirectory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
#define NazaraAssert(a, err) if (!(a)) NzError::Error(nzErrorType_AssertFailed, err, __LINE__, NzDirectory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
#else
#define NazaraAssert(a, err)
#endif
#define NazaraError(err) NzError(nzErrorType_Normal, err, __LINE__, NzDirectory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
#define NazaraInternalError(err) NzError(nzErrorType_Internal, err, __LINE__, NzDirectory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
#define NazaraWarning(err) NzError(nzErrorType_Warning, err, __LINE__, NzDirectory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
#define NazaraError(err) NzError::Error(nzErrorType_Normal, err, __LINE__, NzDirectory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
#define NazaraInternalError(err) NzError::Error(nzErrorType_Internal, err, __LINE__, NzDirectory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
#define NazaraWarning(err) NzError::Error(nzErrorType_Warning, err, __LINE__, NzDirectory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
NAZARA_API void NzError(nzErrorType type, const NzString& error, unsigned int line, const char* file, const char* function);
NAZARA_API unsigned int NzGetLastSystemErrorCode();
NAZARA_API NzString NzGetLastSystemError(unsigned int code = NzGetLastSystemErrorCode());
class NAZARA_API NzError
{
public:
NzError() = delete;
~NzError() = delete;
static void Error(nzErrorType type, const NzString& error);
static void Error(nzErrorType type, const NzString& error, unsigned int line, const char* file, const char* function);
static nzUInt32 GetFlags();
static NzString GetLastError(const char** file = nullptr, unsigned int* line = nullptr, const char** function = nullptr);
static unsigned int GetLastSystemErrorCode();
static NzString GetLastSystemError(unsigned int code = GetLastSystemErrorCode());
static void SetFlags(nzUInt32 flags);
private:
static nzUInt32 s_flags;
static NzString s_lastError;
static const char* s_lastErrorFunction;
static const char* s_lastErrorFile;
static unsigned int s_lastErrorLine;
};
#endif // NAZARA_ERROR_HPP

View File

@@ -0,0 +1,28 @@
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_ERRORFLAGS_HPP
#define NAZARA_ERRORFLAGS_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Enums.hpp>
#include <Nazara/Core/NonCopyable.hpp>
class NzErrorFlags : NzNonCopyable
{
public:
NzErrorFlags(nzUInt32 flags, bool replace = false);
~NzErrorFlags();
nzUInt32 GetPreviousFlags() const;
void SetFlags(nzUInt32 flags, bool replace = false);
private:
nzUInt32 m_previousFlags;
};
#endif // NAZARA_ERRORFLAGS_HPP

View File

@@ -43,6 +43,7 @@ class NAZARA_API NzLog : NzNonCopyable
void SetFile(const NzString& filePath);
void Write(const NzString& string);
void WriteError(nzErrorType type, const NzString& error);
void WriteError(nzErrorType type, const NzString& error, unsigned int line, const NzString& file, const NzString& func);
static NzLog* Instance();