#pragma once #include "../string/String.hpp" #include "../common/errors.hpp" #include <iostream> namespace sprawl { inline void PrintTo(sprawl::String const& value, std::ostream* stream) { *stream << value.toStdString(); } } #if SPRAWL_EXCEPTIONS_ENABLED # define ASSERT_NO_SPRAWL_EXCEPT(expression) do { try{ (expression); } catch(sprawl::ExceptionBase& e) { ASSERT_TRUE(false) << " Expression " #expression << " threw an exception: " << e.what(); } } while(false) # define ABORT_ON_SPRAWL_EXCEPT(expression) do { try{ (expression); } catch(sprawl::ExceptionBase& e) { std::cerr << " Expression " #expression << " threw an exception: " << e.what(); std::terminate(); } } while(false) #else # define ASSERT_NO_SPRAWL_EXCEPT(expression) do { auto error__ = (expression); if(error__.Error()) { ASSERT_TRUE(false) << " Expression " #expression << " threw an exception: " << error__.ErrorString(); } } while(false) # define ABORT_ON_SPRAWL_EXCEPT(expression) do { auto error__ = (expression); if(error__.Error()) { std::cerr << " Expression " #expression << " threw an exception: " << error__.ErrorString(); std::terminate(); } } while(false) #endif
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 16768 | ShadauxCat |
Improvements to error handling in builds with exceptions disabled: - In debug builds or with SPRAWL_ERRORSTATE_STRICT enabled, ErrorState will output a message to stderr and terminate if Get() is called when an error flag is set. (In release buils or with SPRAWL_ERRORSTATE_PERMISSIVE defined, Get() will return junk memory in this case.) - In debug builds or with SPRAWL_ERRORSTATE_STRICT enabled, ErrorState will output a message to stderr and terminate if its destructor is called without checking the errorstate if an error is present (equivalent to an exception terminating the application if no catch() block is present for it). - On linux builds and when running "Analyze" through visual studio, a warning will be issued if any function returning ErrorState has its return value ignored. (This only applies to builds with exceptions not enabled; when exceptions are enabled no warning is issued) - Many functions that could return ErrorState were having their return values silently ignored in internal sprawl code so the user would not find out about errors if exceptions are disabled; now anything in sprawl code that calls a function returning ErrorState will either handle the error, or (in most cases) surface it back up to the user. - As a positive side-effect of the warnings for ignoring ErrorState, several constructors that were capable of throwing exceptions are no longer capable of doing so. #review-16769 |