Make C++ exception works for lua

* Throw exception when open a file fails
This commit is contained in:
Eduardo Bart
2012-06-25 19:42:38 -03:00
parent 98a1b611bf
commit 472e78d368
5 changed files with 18 additions and 24 deletions

View File

@@ -122,11 +122,11 @@ bool InputMessage::canRead(int bytes)
void InputMessage::checkRead(int bytes)
{
if(!canRead(bytes))
g_lua.throwError("InputMessage eof reached");
throw stdext::exception("InputMessage eof reached");
}
void InputMessage::checkWrite(int bytes)
{
if(bytes > BUFFER_MAXSIZE)
g_lua.throwError("InputMessage max buffer size reached");
throw stdext::exception("InputMessage max buffer size reached");
}

View File

@@ -71,7 +71,7 @@ void OutputMessage::addString(const std::string& buffer)
{
int len = buffer.length();
if(len > MAX_STRING_LENGTH)
g_lua.throwError(stdext::format("string length > %d", MAX_STRING_LENGTH));
throw stdext::exception(stdext::format("string length > %d", MAX_STRING_LENGTH));
checkWrite(len + 2);
addU16(len);
memcpy((char*)(m_buffer + m_writePos), buffer.c_str(), len);
@@ -92,7 +92,7 @@ void OutputMessage::addPaddingBytes(int bytes, uint8 byte)
void OutputMessage::encryptRSA(int size, const std::string& key)
{
if(m_messageSize < size)
g_lua.throwError("insufficient bytes in buffer to encrypt");
throw stdext::exception("insufficient bytes in buffer to encrypt");
RSA::encrypt((char*)m_buffer + m_writePos - size, size, key.c_str());
}
@@ -124,5 +124,5 @@ bool OutputMessage::canWrite(int bytes)
void OutputMessage::checkWrite(int bytes)
{
if(!canWrite(bytes))
g_lua.throwError("OutputMessage max buffer size reached");
throw stdext::exception("OutputMessage max buffer size reached");
}