Documentation for Error
Former-commit-id: 9158cb014b813739b09b0bea7c375dc549815aef
This commit is contained in:
parent
99370683b3
commit
ff51b90748
|
|
@ -18,11 +18,30 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
/*!
|
||||||
|
* \class Nz::Error
|
||||||
|
* \brief Core class that represents an error
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Gets the flags of the error
|
||||||
|
* \return Flag
|
||||||
|
*/
|
||||||
|
|
||||||
UInt32 Error::GetFlags()
|
UInt32 Error::GetFlags()
|
||||||
{
|
{
|
||||||
return s_flags;
|
return s_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Gets the last error
|
||||||
|
* \return Last error
|
||||||
|
*
|
||||||
|
* \param file Optional argument to set last error file
|
||||||
|
* \param line Optional argument to set last error line
|
||||||
|
* \param function Optional argument to set last error function
|
||||||
|
*/
|
||||||
|
|
||||||
String Error::GetLastError(const char** file, unsigned int* line, const char** function)
|
String Error::GetLastError(const char** file, unsigned int* line, const char** function)
|
||||||
{
|
{
|
||||||
if (file)
|
if (file)
|
||||||
|
|
@ -37,6 +56,11 @@ namespace Nz
|
||||||
return s_lastError;
|
return s_lastError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Gets the last system error code
|
||||||
|
* \return "errno"
|
||||||
|
*/
|
||||||
|
|
||||||
unsigned int Error::GetLastSystemErrorCode()
|
unsigned int Error::GetLastSystemErrorCode()
|
||||||
{
|
{
|
||||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||||
|
|
@ -49,6 +73,13 @@ namespace Nz
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Gets the string representation of the last system error code
|
||||||
|
* \return Message of the error
|
||||||
|
*
|
||||||
|
* \param code Code of the error
|
||||||
|
*/
|
||||||
|
|
||||||
String Error::GetLastSystemError(unsigned int code)
|
String Error::GetLastSystemError(unsigned int code)
|
||||||
{
|
{
|
||||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||||
|
|
@ -65,7 +96,7 @@ namespace Nz
|
||||||
String error(String::Unicode(buffer));
|
String error(String::Unicode(buffer));
|
||||||
LocalFree(buffer);
|
LocalFree(buffer);
|
||||||
|
|
||||||
error.Trim(); // Pour une raison inconnue, Windows met deux-trois retours à la ligne après le message
|
error.Trim(); // For an unknown reason, Windows put two-three line return after the message
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
#elif defined(NAZARA_PLATFORM_POSIX)
|
#elif defined(NAZARA_PLATFORM_POSIX)
|
||||||
|
|
@ -77,11 +108,27 @@ namespace Nz
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Sets the flags
|
||||||
|
*
|
||||||
|
* \param flags Flags for the error
|
||||||
|
*/
|
||||||
|
|
||||||
void Error::SetFlags(UInt32 flags)
|
void Error::SetFlags(UInt32 flags)
|
||||||
{
|
{
|
||||||
s_flags = flags;
|
s_flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Checks if the error should trigger
|
||||||
|
*
|
||||||
|
* \param type ErrorType of the error
|
||||||
|
* \param error Message of the error
|
||||||
|
*
|
||||||
|
* \remark Produces a std::abort on AssertFailed with NAZARA_CORE_EXIT_ON_ASSERT_FAILURE defined
|
||||||
|
* \remark Produces a std::runtime_error on AssertFailed or throwing exception
|
||||||
|
*/
|
||||||
|
|
||||||
void Error::Trigger(ErrorType type, const String& error)
|
void Error::Trigger(ErrorType type, const String& error)
|
||||||
{
|
{
|
||||||
if (type == ErrorType_AssertFailed || (s_flags & ErrorFlag_Silent) == 0 || (s_flags & ErrorFlag_SilentDisabled) != 0)
|
if (type == ErrorType_AssertFailed || (s_flags & ErrorFlag_Silent) == 0 || (s_flags & ErrorFlag_SilentDisabled) != 0)
|
||||||
|
|
@ -102,6 +149,19 @@ namespace Nz
|
||||||
throw std::runtime_error(error);
|
throw std::runtime_error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Checks if the error should trigger
|
||||||
|
*
|
||||||
|
* \param type ErrorType of the error
|
||||||
|
* \param error Message of the error
|
||||||
|
* \param line Line of the error
|
||||||
|
* \param file File of the error
|
||||||
|
* \param function Function of the error
|
||||||
|
*
|
||||||
|
* \remark Produces a std::abort on AssertFailed with NAZARA_CORE_EXIT_ON_ASSERT_FAILURE defined
|
||||||
|
* \remark Produces a std::runtime_error on AssertFailed or throwing exception
|
||||||
|
*/
|
||||||
|
|
||||||
void Error::Trigger(ErrorType type, const String& error, unsigned int line, const char* file, const char* function)
|
void Error::Trigger(ErrorType type, const String& error, unsigned int line, const char* file, const char* function)
|
||||||
{
|
{
|
||||||
if (type == ErrorType_AssertFailed || (s_flags & ErrorFlag_Silent) == 0 || (s_flags & ErrorFlag_SilentDisabled) != 0)
|
if (type == ErrorType_AssertFailed || (s_flags & ErrorFlag_Silent) == 0 || (s_flags & ErrorFlag_SilentDisabled) != 0)
|
||||||
|
|
|
||||||
|
|
@ -8,22 +8,50 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
/*!
|
||||||
|
* \class Nz::ErrorFlags
|
||||||
|
* \brief Core class that represents flags for error
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Constructs a ErrorFlags object with flags
|
||||||
|
*
|
||||||
|
* \param flags Flags for the error
|
||||||
|
* \param replace Replace the entirely the old flag if true, else do a "OR"
|
||||||
|
*/
|
||||||
|
|
||||||
ErrorFlags::ErrorFlags(UInt32 flags, bool replace) :
|
ErrorFlags::ErrorFlags(UInt32 flags, bool replace) :
|
||||||
m_previousFlags(Error::GetFlags())
|
m_previousFlags(Error::GetFlags())
|
||||||
{
|
{
|
||||||
SetFlags(flags, replace);
|
SetFlags(flags, replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Destructs the object and sets the old flag
|
||||||
|
*/
|
||||||
|
|
||||||
ErrorFlags::~ErrorFlags()
|
ErrorFlags::~ErrorFlags()
|
||||||
{
|
{
|
||||||
Error::SetFlags(m_previousFlags);
|
Error::SetFlags(m_previousFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Gets the previous flag
|
||||||
|
* \return Previous flag
|
||||||
|
*/
|
||||||
|
|
||||||
UInt32 ErrorFlags::GetPreviousFlags() const
|
UInt32 ErrorFlags::GetPreviousFlags() const
|
||||||
{
|
{
|
||||||
return m_previousFlags;
|
return m_previousFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Sets the flags
|
||||||
|
*
|
||||||
|
* \param flags Flags for the error
|
||||||
|
* \param replace Replace the entirely the old flag if true, else do a "OR"
|
||||||
|
*/
|
||||||
|
|
||||||
void ErrorFlags::SetFlags(UInt32 flags, bool replace)
|
void ErrorFlags::SetFlags(UInt32 flags, bool replace)
|
||||||
{
|
{
|
||||||
if (!replace)
|
if (!replace)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue