Tidy up some use of Error for throw

This commit is contained in:
Vinnie Falco
2013-09-28 18:15:00 -07:00
parent e5e0f527fe
commit 4394594518
13 changed files with 34 additions and 75 deletions

View File

@@ -34,10 +34,6 @@ namespace vf
namespace namespace
{ {
//
// While this object is in scope, any Windows SEH
// exceptions will be caught and re-thrown as an Error object.
//
class ScopedPlatformExceptionCatcher : public Uncopyable class ScopedPlatformExceptionCatcher : public Uncopyable
{ {
public: public:
@@ -155,7 +151,7 @@ public:
break; break;
} }
Throw (Error ().fail (__FILE__, __LINE__, s, Error::platform)); beast_reportFatalError (s, __FILE__, __LINE__);
} }
return s_sehPrev (ei); return s_sehPrev (ei);
@@ -218,26 +214,6 @@ bool CatchAny (Function <void (void)> f, bool returnFromException)
caughtException = false; caughtException = false;
} }
catch (Error& e)
{
if (!returnFromException)
{
JUCEApplication* app = JUCEApplication::getInstance ();
if (app)
{
app->unhandledException (
&e,
e.getSourceFilename (),
e.getLineNumber ());
}
else
{
std::cout << e.what ();
std::unexpected ();
}
}
}
catch (std::exception& e) catch (std::exception& e)
{ {
if (!returnFromException) if (!returnFromException)

View File

@@ -115,7 +115,7 @@ public:
const size_t bytesNeeded = headerBytes + bytes; const size_t bytesNeeded = headerBytes + bytes;
if (bytesNeeded > m_allocator.m_pages->getPageBytes ()) if (bytesNeeded > m_allocator.m_pages->getPageBytes ())
Throw (Error ().fail (__FILE__, __LINE__, TRANS ("the memory request was too large"))); fatal_error ("the memory request was too large");
Header* header; Header* header;

View File

@@ -144,7 +144,7 @@ FifoFreeStoreWithoutTLS::FifoFreeStoreWithoutTLS ()
: m_pages (GlobalPagedFreeStore::getInstance ()) : m_pages (GlobalPagedFreeStore::getInstance ())
{ {
if (m_pages->getPageBytes () < sizeof (Block) + 256) if (m_pages->getPageBytes () < sizeof (Block) + 256)
Throw (Error ().fail (__FILE__, __LINE__, TRANS ("the block size is too small"))); fatal_error ("the block size is too small");
m_active = newBlock (); m_active = newBlock ();
} }
@@ -161,7 +161,7 @@ void* FifoFreeStoreWithoutTLS::allocate (const size_t bytes)
const size_t actual = sizeof (Header) + bytes; const size_t actual = sizeof (Header) + bytes;
if (actual > m_pages->getPageBytes ()) if (actual > m_pages->getPageBytes ())
Throw (Error ().fail (__FILE__, __LINE__, TRANS ("the memory request was too large"))); fatal_error ("the memory request was too large");
Header* h; Header* h;

View File

@@ -123,16 +123,14 @@ void* PagedFreeStore::allocate ()
const bool exhausted = m_newPagesLeft.release (); const bool exhausted = m_newPagesLeft.release ();
if (exhausted) if (exhausted)
Throw (Error ().fail (__FILE__, __LINE__, fatal_error ("the limit of memory allocations was reached");
TRANS ("the limit of memory allocations was reached")));
#endif #endif
void* storage = ::malloc (m_pageBytes); void* storage = ::malloc (m_pageBytes);
if (!storage) if (!storage)
Throw (Error ().fail (__FILE__, __LINE__, fatal_error ("a memory allocation failed");
TRANS ("a memory allocation failed")));
page = new (storage) Page (this); page = new (storage) Page (this);

View File

@@ -46,7 +46,7 @@ public:
inline void* allocate (const size_t bytes) inline void* allocate (const size_t bytes)
{ {
if (bytes > m_pageBytes) if (bytes > m_pageBytes)
Throw (Error ().fail (__FILE__, __LINE__, "the size is too large")); fatal_error ("the size is too large");
return allocate (); return allocate ();
} }

View File

@@ -64,7 +64,7 @@ bool Result::operator!= (const Result& other) const noexcept
Result Result::fail (const String& errorMessage) noexcept Result Result::fail (const String& errorMessage) noexcept
{ {
return Result (errorMessage.isEmpty() ? "Unknown Error" : errorMessage); return Result (errorMessage.isEmpty() ? "Unknown error" : errorMessage);
} }
const String& Result::getErrorMessage() const noexcept const String& Result::getErrorMessage() const noexcept

View File

@@ -380,7 +380,7 @@ ListenersBase::Proxy::Proxy (void const* const member, const size_t bytes)
: m_bytes (bytes) : m_bytes (bytes)
{ {
if (bytes > maxMemberBytes) if (bytes > maxMemberBytes)
Throw (Error ().fail (__FILE__, __LINE__, "the Proxy member is too large")); fatal_error ("the Proxy member is too large");
memcpy (m_member, member, bytes); memcpy (m_member, member, bytes);
} }

View File

@@ -72,9 +72,7 @@ struct type_conversion
static void from_base(base_type const& in, indicator ind, T& out) static void from_base(base_type const& in, indicator ind, T& out)
{ {
// null not allowed // null not allowed
if (ind == i_null) check_precondition (ind != i_null);
Throw(Error().fail(__FILE__, __LINE__));
out = in; out = in;
} }

View File

@@ -97,8 +97,7 @@ void standard_into_type::do_into()
if (colType == SQLITE_NULL) if (colType == SQLITE_NULL)
{ {
// null encountered with no indicator // null encountered with no indicator
if (!m_ind) check_precondition (m_ind != nullptr);
Throw(Error().fail(__FILE__, __LINE__));
*m_ind = i_null; *m_ind = i_null;
} }
@@ -164,7 +163,7 @@ void standard_into_type::do_into()
break; break;
default: default:
Throw(Error().fail(__FILE__, __LINE__)); fatal_error ("unknown case");
} }
} }
break; break;
@@ -188,7 +187,7 @@ void standard_into_type::do_into()
break; break;
default: default:
Throw(Error().fail(__FILE__, __LINE__)); fatal_error ("unknown case");
}; };
} }
break; break;
@@ -208,7 +207,7 @@ void standard_into_type::do_into()
break; break;
case x_stdwstring: case x_stdwstring:
Throw(Error().fail(__FILE__, __LINE__)); fatal_error ("invalid case");
break; break;
case x_beastString: case x_beastString:
@@ -276,7 +275,7 @@ void standard_into_type::do_into()
break; break;
default: default:
Throw(Error().fail(__FILE__, __LINE__)); fatal_error ("unknown case");
} }
} }
@@ -286,10 +285,10 @@ void standard_into_type::do_into()
break; break;
case SQLITE_BLOB: case SQLITE_BLOB:
Throw(Error().fail(__FILE__, __LINE__)); fatal_error ("invalid case");
default: default:
Throw(Error().fail(__FILE__, __LINE__)); fatal_error ("unknown case");
}; };
} }

View File

@@ -67,14 +67,12 @@ public:
{ {
int threadSafe = sqlite3_threadsafe(); int threadSafe = sqlite3_threadsafe();
if (threadSafe == 0) check_precondition (threadSafe != 0);
Throw(Error().fail(__FILE__, __LINE__, Error::assertFailed));
#if 0 #if 0
int result = sqlite3_config(SQLITE_CONFIG_MULTITHREAD); int result = sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
if (result != SQLITE_OK) check_postcondition (result == SQLITE_OK);
Throw(Error().fail(__FILE__, __LINE__, Error::assertFailed));
#endif #endif
sqlite3_initialize(); sqlite3_initialize();
@@ -115,8 +113,7 @@ session::~session()
Error session::clone() Error session::clone()
{ {
if (m_connection) check_precondition (! m_connection);
Throw(Error().fail(__FILE__, __LINE__)); // already open
return open(m_fileName, m_connectString); return open(m_fileName, m_connectString);
} }
@@ -134,8 +131,7 @@ Error session::open(String fileName, std::string options)
Error err; Error err;
// can't open twice // can't open twice
if (m_connection) check_precondition (! m_connection);
Throw(err.fail(__FILE__, __LINE__, Error::fileInUse));
int mode = 0; int mode = 0;
int flags = 0; int flags = 0;
@@ -183,13 +179,12 @@ Error session::open(String fileName, std::string options)
} }
else else
{ {
Throw(err.fail(__FILE__, __LINE__, Error::badParameter)); fatal_error ("bad parameter");
} }
} }
else else
{ {
// duplicate fatal_error ("duplicate parameter");
Throw(err.fail(__FILE__, __LINE__, Error::badParameter));
} }
} }
@@ -210,13 +205,12 @@ Error session::open(String fileName, std::string options)
} }
else else
{ {
Throw(err.fail(__FILE__, __LINE__, Error::badParameter)); fatal_error ("bad parameter");
} }
} }
else else
{ {
// duplicate fatal_error ("duplicate parameter");
Throw(err.fail(__FILE__, __LINE__, Error::badParameter));
} }
} }
@@ -235,19 +229,17 @@ Error session::open(String fileName, std::string options)
} }
else else
{ {
Throw(err.fail(__FILE__, __LINE__, Error::badParameter)); fatal_error ("bad parameter");
} }
} }
else else
{ {
// duplicate fatal_error ("duplicate parameter");
Throw(err.fail(__FILE__, __LINE__, Error::badParameter));
} }
} }
else else
{ {
// unknown option fatal_error ("unknown parameter");
Throw(err.fail(__FILE__, __LINE__, Error::badParameter));
} }
} }

View File

@@ -180,8 +180,7 @@ Error statement_imp::execute()
{ {
Error error; Error error;
if (!m_stmt) check_precondition (m_stmt != nullptr);
Throw(Error().fail(__FILE__, __LINE__, Error::badParameter));
// ??? // ???
m_bGotData = false; m_bGotData = false;
@@ -253,7 +252,7 @@ bool statement_imp::fetch(Error& error)
else else
{ {
// should never get SQLITE_OK here // should never get SQLITE_OK here
Throw(Error().fail(__FILE__, __LINE__, Error::assertFailed)); fatal_error ("invalid result");
} }
return m_bGotData; return m_bGotData;

View File

@@ -77,8 +77,7 @@ Error transaction::commit()
Error error; Error error;
// already handled // already handled
if (m_bHandled) check_precondition (!m_bHandled);
Throw(Error().fail(__FILE__, __LINE__));
// if commit() throws, m_bHandled will remain false // if commit() throws, m_bHandled will remain false
// and the destructor will attempt a rollback. // and the destructor will attempt a rollback.
@@ -93,8 +92,7 @@ Error transaction::commit()
void transaction::rollback() void transaction::rollback()
{ {
// already handled // already handled
if (m_bHandled) check_precondition (!m_bHandled);
Throw(Error().fail(__FILE__, __LINE__));
m_session.rollback(); m_session.rollback();
m_bHandled = true; m_bHandled = true;

View File

@@ -87,8 +87,7 @@ inline T const& as(void const* v)
{ {
T const& val = *static_cast <T const*>(v); T const& val = *static_cast <T const*>(v);
if (val > T(std::numeric_limits<L>::max())) check_precondition (val <= T(std::numeric_limits<L>::max()));
Throw(Error().fail(__FILE__, __LINE__));
return val; return val;
} }
@@ -203,7 +202,7 @@ void standard_use_type::do_use()
case x_stdtm: case x_stdtm:
case x_blob: case x_blob:
default: default:
Throw(Error().fail(__FILE__, __LINE__, Error::badParameter)); fatal_error ("bad parameter");
} }
if (result != SQLITE_OK) if (result != SQLITE_OK)