📄 mal_exception.c
字号:
#line 164 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_exception.mx"#include "mal_config.h"#include "mal_exception.h"static char *exceptionNames[] = {/* 0 */ "MALException",/* 1 */ "IllegalArgumentException",/* 2 */ "OutOfBoundsException",/* 3 */ "IOException",/* 4 */ "InvalidCredentialsException",/* 5 */ "OptimizerException",/* 6 */ "StackOverflowException",/* 7 */ "SyntaxException",/* 8 */ "TypeException",/* 9 */ "LoaderException",/*10 */ "ParseException",/*11 */ "ArithmeticException",/*12 */ "PermissionDeniedException",/*13 */ "SQLException",/*EOE*/ NULL};/** * Internal helper function for createException and * showException such that they share the same code, because reuse * is good. */static strcreateExceptionInternal(enum malexception type, str fcn, str format, va_list ap){ char message[GDKMAXERRLEN]; int len;#ifdef _DEBUG_EXCEPTION_ printf("exception:%s:%s\n",fcn,format);#endif len = snprintf(message, GDKMAXERRLEN - 1, "%s:%s:", exceptionNames[type], fcn); len += vsnprintf(message + len, GDKMAXERRLEN - 1 - len, format, ap); message[len] = '\0'; return(GDKstrdup(message));}/** * Returns an exception string for the given type of exception, function * and additional formatting parameters. This function will crash the * system or return bogus when the malexception enum is not aligned with * the exceptionNames array. */strcreateException(enum malexception type, str fcn, str format, ...){ va_list ap; str ret; va_start(ap, format); ret = createExceptionInternal(type, fcn, format, ap); va_end(ap); return(ret);}/** * Internal helper function to properly emit the given string to GDKout, * thereby abiding to all the protocol laws. This function will bluntly * crash if the given string (pointer) is NULL. */static voiddumpToGDKout(str whatever) { size_t i; size_t last = 0; size_t len = strlen(whatever); /* yes, crash if whatever is NULL */ /* make sure each line starts with a ! */ for (i = 0; i < len; i++) { if (whatever[i] == '\n') { whatever[i] = '\0'; if (i - last > 0) /* skip empty lines */ stream_printf(GDKout, "!%s\n", whatever + last); last = i + 1; } } /* flush last part */ if (i - last > 0) /* skip if empty */ stream_printf(GDKout, "!%s\n", whatever + last);}/** * Dump an error message using the exception structure using the primary * console as defined by GDKout. */voidshowException(enum malexception type, str fcn, str format, ...){ va_list ap; str msg; va_start(ap, format); msg = createExceptionInternal(type, fcn, format, ap); va_end(ap); dumpToGDKout(msg); GDKfree(msg);}/** * Internal helper function for createScriptException and * showScriptException such that they share the same code, because reuse * is good. */static strcreateScriptExceptionInternal(MalBlkPtr mb, int pc, enum malexception type, str prev, str format, va_list ap){ char buf[GDKMAXERRLEN]; size_t i; str s, fcn; s = mb ? getModName(mb) : "unknown"; fcn = mb ? getFcnName(mb) : "unknown"; i = 0; if (prev) i += snprintf(buf + i, GDKMAXERRLEN - 1 - i, "%s\n", prev); i += snprintf(buf + i, GDKMAXERRLEN - 1 - i, "%s:%s.%s[%d]:", exceptionNames[type], s, fcn, pc); i += vsnprintf(buf + i, GDKMAXERRLEN - 1 - i, format, ap); buf[i] = '\0'; return GDKstrdup(buf);}/** * Returns an exception string for the use of MAL scripts. These * exceptions are newline terminated, and determine module and function * from the given MalBlkPtr. An old exception can be given, such that * this exception is chained to the previous one. Conceptually this * creates a "stack" of exceptions. * This function will crash the system or return bogus when the * malexception enum is not aligned with the exceptionNames array. */strcreateScriptException(MalBlkPtr mb, int pc, enum malexception type, str prev, str format, ...){ va_list ap; str ret; va_start(ap, format); ret = createScriptExceptionInternal(mb, pc, type, prev, format, ap); va_end(ap); return(ret);}/** * Sends the exception as generated by a call to * createScriptException(mb, pc, type, NULL, format, ...) to the console * defined by GDKout. */voidshowScriptException(MalBlkPtr mb, int pc, enum malexception type, str format, ...){ va_list ap; str msg; va_start(ap, format); msg = createScriptExceptionInternal(mb, pc, type, NULL, format, ap); va_end(ap); dumpToGDKout(msg); GDKfree(msg);}/** * Returns the malexception number for the given exception string. If no * exception could be found in the string, MAL is returned indicating a * generic MALException. */enum malexceptiongetExceptionType(str exception){ enum malexception ret = MAL; str s; enum malexception i; if ((s = strchr(exception, ':')) != NULL) *s = '\0'; for (i = MAL; exceptionNames[i] != NULL; i++) { if (strcmp(exceptionNames[i], exception) == 0) { ret = i; break; } } /* restore original string */ if (s != NULL) *s = ':'; return(ret);}/** * Returns the location the exception was raised, if known. It depends * on the how the exception was created, what the location looks like. * The returned string is mallocced with GDKmalloc, and hence needs to * be GDKfreed. */strgetExceptionPlace(str exception){ str ret; str s, t; if ((s = strchr(exception, ':')) != NULL && (t = strchr(s + 1, ':')) != NULL) { *t = '\0'; ret = GDKstrdup(s + 1); *t = ':'; return(ret); } else { return(GDKstrdup("(unknown)")); }}/** * Returns the informational message of the exception given. */strgetExceptionMessage(str exception){ str s, t; if ((s = strchr(exception, ':')) != NULL) { /* skip the place, if there */ if ((t = strchr(s + 1, ':')) != NULL) s = t; return(s + 1); } else { return(exception); }}/** * Returns the string representation of the given exception. This is * the string as used when creating an exception of the same type. */strexceptionToString(enum malexception e){ return(exceptionNames[e]);}#line 417 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_exception.mx"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -