59 lines
1.2 KiB
Plaintext
59 lines
1.2 KiB
Plaintext
|
|
#if !defined(BAD_APPLE_OS_EXCEPTION_INCLUDED)
|
|
#define BAD_APPLE_OS_EXCEPTION_INCLUDED
|
|
|
|
#include <cstdlib>
|
|
#if defined(__baos_kernel_source__)
|
|
#include "os/panic.hpp"
|
|
#endif
|
|
|
|
#if defined(__cpp_exceptions)
|
|
#define __ba_throw throw
|
|
#else
|
|
#define __ba_throw ba::impl::gAbortHelper(__FILE__, __LINE__) =
|
|
#endif
|
|
|
|
namespace std
|
|
{
|
|
class exception
|
|
{
|
|
public:
|
|
virtual ~exception() noexcept = default;
|
|
virtual const char* what() const noexcept;
|
|
};
|
|
}
|
|
|
|
#if !defined(__cpp_exceptions)
|
|
namespace ba::impl
|
|
{
|
|
struct ExceptionAbortHelper
|
|
{
|
|
private:
|
|
const char* mFile = "<unknown>";
|
|
int mLine = -1;
|
|
public:
|
|
[[noreturn]] ExceptionAbortHelper& operator=(const std::exception& ex) noexcept
|
|
{
|
|
#if defined(__baos_kernel_source__)
|
|
panicf("Uncaught exception with message \"%s\" at %s:%d.", ex.what(), mFile, mLine);
|
|
#else
|
|
// TODO!!!
|
|
std::abort();
|
|
__builtin_unreachable();
|
|
#endif
|
|
}
|
|
|
|
ExceptionAbortHelper& operator()(const char* file, int line) noexcept
|
|
{
|
|
mFile = file;
|
|
mLine = line;
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
extern ExceptionAbortHelper gAbortHelper;
|
|
}
|
|
#endif // !defined(__cpp_exceptions)
|
|
|
|
#endif // !defined(BAD_APPLE_OS_EXCEPTION_INCLUDED)
|