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
{
//
// While this object is in scope, any Windows SEH
// exceptions will be caught and re-thrown as an Error object.
//
class ScopedPlatformExceptionCatcher : public Uncopyable
{
public:
@@ -155,7 +151,7 @@ public:
break;
}
Throw (Error ().fail (__FILE__, __LINE__, s, Error::platform));
beast_reportFatalError (s, __FILE__, __LINE__);
}
return s_sehPrev (ei);
@@ -218,26 +214,6 @@ bool CatchAny (Function <void (void)> f, bool returnFromException)
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)
{
if (!returnFromException)

View File

@@ -115,7 +115,7 @@ public:
const size_t bytesNeeded = headerBytes + bytes;
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;

View File

@@ -144,7 +144,7 @@ FifoFreeStoreWithoutTLS::FifoFreeStoreWithoutTLS ()
: m_pages (GlobalPagedFreeStore::getInstance ())
{
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 ();
}
@@ -161,7 +161,7 @@ void* FifoFreeStoreWithoutTLS::allocate (const size_t bytes)
const size_t actual = sizeof (Header) + bytes;
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;

View File

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

View File

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

View File

@@ -64,7 +64,7 @@ bool Result::operator!= (const Result& other) const 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

View File

@@ -380,7 +380,7 @@ ListenersBase::Proxy::Proxy (void const* const member, const size_t bytes)
: m_bytes (bytes)
{
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);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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