mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-03-14 16:17:13 +01:00
Fix the exception code and make it use pooled buffers instead of the common buffer.
This commit is contained in:
parent
01bafd7c4f
commit
3762b5e2ca
@ -102,18 +102,21 @@ bool SToB(CSStr str)
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void SqThrowF(CCStr fmt, ...)
|
void SqThrowF(CCStr fmt, ...)
|
||||||
{
|
{
|
||||||
|
// Acquire a moderately sized buffer
|
||||||
|
Buffer b(128);
|
||||||
// Initialize the argument list
|
// Initialize the argument list
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start (args, fmt);
|
va_start (args, fmt);
|
||||||
// Write the requested contents
|
// Attempt to run the specified format
|
||||||
if (snprintf(g_Buffer, sizeof(g_Buffer), fmt, args) < 0)
|
if (b.WriteF(0, fmt, args) == 0)
|
||||||
{
|
{
|
||||||
strcpy(g_Buffer, "Unknown error has occurred");
|
// Attempt to write a generic message at least
|
||||||
|
b.At(b.WriteS(0, "Unknown error has occurred")) = '\0';
|
||||||
}
|
}
|
||||||
// Release the argument list
|
// Release the argument list
|
||||||
va_end(args);
|
va_end(args);
|
||||||
// Throw the exception with the resulted message
|
// Throw the exception with the resulted message
|
||||||
throw Sqrat::Exception(g_Buffer);
|
throw Sqrat::Exception(b.Get< SQChar >());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
@ -121,7 +124,7 @@ CSStr ToStrF(CCStr fmt, ...)
|
|||||||
{
|
{
|
||||||
// Prepare the arguments list
|
// Prepare the arguments list
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start (args, fmt);
|
va_start(args, fmt);
|
||||||
// Attempt to run the specified format
|
// Attempt to run the specified format
|
||||||
int ret = vsnprintf(g_Buffer, sizeof(g_Buffer), fmt, args);
|
int ret = vsnprintf(g_Buffer, sizeof(g_Buffer), fmt, args);
|
||||||
// See if the format function failed
|
// See if the format function failed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user