-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Misc] Renamed Throw.h to Trap.h and made Trap() publicly available.
This builds upon the new way to better handle exceptions in the public interface (671c74e). Instead of only calling abort() when exceptions are disabled, this change makes use of the already implemented Trap() function that provides a full callstack and other functionality. Since LLGL does not handle but only throws exceptions, we accept that this only provides a handful of predefined exceptions for the few cases they are used in the public header files.
- Loading branch information
1 parent
f93409e
commit e8d86d7
Showing
11 changed files
with
140 additions
and
96 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Trap.h | ||
* | ||
* Copyright (c) 2015 Lukas Hermanns. All rights reserved. | ||
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt). | ||
*/ | ||
|
||
#ifndef LLGL_TRAP_H | ||
#define LLGL_TRAP_H | ||
|
||
|
||
#include <LLGL/Export.h> | ||
|
||
|
||
/** | ||
\brief Helper macro to trap execution when the condition fails. | ||
\remarks LLGL only throws exceptions if it was built with \c LLGL_ENABLE_EXCEPTIONS. | ||
\see LLGL::Trap | ||
*/ | ||
#define LLGL_VERIFY(CONDITION, EXCEPTION) \ | ||
if (!(CONDITION)) \ | ||
{ \ | ||
LLGL::Trap(LLGL::Exception::EXCEPTION, __FUNCTION__, "assertion failed: %s", #CONDITION); \ | ||
} | ||
|
||
|
||
namespace LLGL | ||
{ | ||
|
||
|
||
/** | ||
\brief Enumeration of all exception classes Trap() can throw. | ||
\remarks LLGL only throws exceptions if it was built with \c LLGL_ENABLE_EXCEPTIONS. | ||
\see Trap | ||
*/ | ||
enum class Exception | ||
{ | ||
//! Refers to std::runtime_error. | ||
RuntimeError, | ||
|
||
//! Refers to std::out_of_range. | ||
OutOfRange, | ||
|
||
//! Refers to std::bad_cast. | ||
BadCast, | ||
|
||
//! Refers to std::invalid_argument. | ||
InvalidArgument, | ||
}; | ||
|
||
|
||
/** | ||
\brief Primary function to trap execution from an unrecoverable state. | ||
\param[in] exception Specifies what type of exception this function should throw if exceptions are enabled. | ||
\param[in] origin Specifies the origin where execution is trapped. This can be the special preprocessor macro \c __FUNCTION__ for instance. | ||
\param[in] format Specifies the formatted string as used with \c printf. | ||
\remarks This might either throw an exception, abort execution, or break the debugger depending on the configuration LLGL was built with. | ||
LLGL does not handle exceptions of any kind but can throw exceptions (if built with \c LLGL_ENABLE_EXCEPTIONS) | ||
to let the client programmer exit the application gracefully. | ||
Otherwise, this function simply aborts execution and dumps the callstack to the standard error pipe. | ||
*/ | ||
[[noreturn]] | ||
LLGL_EXPORT void Trap(Exception exception, const char* origin, const char* format, ...); | ||
|
||
|
||
} // /namespace LLGL | ||
|
||
|
||
#endif | ||
|
||
|
||
|
||
// ================================================================================ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.