Exception: Constructor now takes printf style arguments
This commit is contained in:
parent
5b736bcfd6
commit
9759e52b3c
|
@ -94,9 +94,7 @@ void raiseRbExc(const Exception &exc)
|
|||
RbData *data = getRbData();
|
||||
VALUE excClass = data->exc[excToRbExc[exc.type]];
|
||||
|
||||
static char buffer[512];
|
||||
exc.snprintf(buffer, sizeof(buffer));
|
||||
rb_raise(excClass, buffer);
|
||||
rb_raise(excClass, exc.msg.c_str());
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -275,9 +275,7 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
|
|||
}
|
||||
catch (const Exception &e)
|
||||
{
|
||||
char buffer[512];
|
||||
snprintf(buffer, sizeof(buffer), e.fmt.c_str(), e.arg1.c_str(), e.arg2.c_str());
|
||||
readError = std::string(": ") + std::string(buffer);
|
||||
readError = std::string(": ") + e.msg;
|
||||
}
|
||||
|
||||
SDL_RWclose(&ops);
|
||||
|
|
|
@ -138,9 +138,7 @@ void raiseMrbExc(mrb_state *mrb, const Exception &exc)
|
|||
MrbData *data = getMrbData(mrb);
|
||||
RClass *excClass = data->exc[excToMrbExc[exc.type]];
|
||||
|
||||
static char buffer[512];
|
||||
exc.snprintf(buffer, sizeof(buffer));
|
||||
mrb_raise(mrb, excClass, buffer);
|
||||
mrb_raise(mrb, excClass, exc.msg.c_str());
|
||||
}
|
||||
|
||||
MRB_METHOD_PUB(inspectObject)
|
||||
|
|
|
@ -548,8 +548,8 @@ read_value(MarshalContext *ctx)
|
|||
break;
|
||||
|
||||
default :
|
||||
throw Exception(Exception::MKXPError, "Marshal.load: unsupported value type '%s'",
|
||||
std::string(1, (char)type));
|
||||
throw Exception(Exception::MKXPError, "Marshal.load: unsupported value type '%c'",
|
||||
(char) type);
|
||||
}
|
||||
|
||||
mrb_gc_arena_restore(mrb, arena);
|
||||
|
|
|
@ -58,6 +58,6 @@ private:
|
|||
|
||||
/* Every cpp needs to define DISP_CLASS_NAME for itself (lowercase) */
|
||||
#define GUARD_DISPOSED \
|
||||
{ if (isDisposed()) throw Exception(Exception::RGSSError, "disposed %S", DISP_CLASS_NAME); }
|
||||
{ if (isDisposed()) throw Exception(Exception::RGSSError, "disposed %s", DISP_CLASS_NAME); }
|
||||
|
||||
#endif // DISPOSABLE_H
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
struct Exception
|
||||
{
|
||||
|
@ -44,19 +45,19 @@ struct Exception
|
|||
};
|
||||
|
||||
Type type;
|
||||
std::string fmt;
|
||||
std::string arg1;
|
||||
std::string arg2;
|
||||
std::string msg;
|
||||
|
||||
Exception(Type type, std::string fmt,
|
||||
std::string arg1 = std::string(),
|
||||
std::string arg2 = std::string())
|
||||
: type(type), fmt(fmt), arg1(arg1), arg2(arg2)
|
||||
{}
|
||||
|
||||
void snprintf(char *buffer, size_t bufSize) const
|
||||
Exception(Type type, const char *format, ...)
|
||||
: type(type)
|
||||
{
|
||||
::snprintf(buffer, bufSize, fmt.c_str(), arg1.c_str(), arg2.c_str());
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
msg.resize(512);
|
||||
vsnprintf(&msg[0], msg.size(), format, ap);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -128,14 +128,9 @@ TEXFBO TexPool::request(int width, int height)
|
|||
|
||||
int maxSize = glState.caps.maxTexSize;
|
||||
if (width > maxSize || height > maxSize)
|
||||
{
|
||||
char buffer[128];
|
||||
snprintf(buffer, sizeof(buffer),
|
||||
"Texture dimensions [%d, %d] exceed hardware capabilities",
|
||||
width, height);
|
||||
|
||||
throw Exception(Exception::MKXPError, buffer);
|
||||
}
|
||||
throw Exception(Exception::MKXPError,
|
||||
"Texture dimensions [%d, %d] exceed hardware capabilities",
|
||||
width, height);
|
||||
|
||||
/* Nope, create it instead */
|
||||
TEXFBO::init(cnode.obj);
|
||||
|
|
Loading…
Reference in New Issue