//-------------------------------------------------------------------------- bool debmod_t::get_exception_name(int code, char *buf, size_t bufsize) { const exception_info_t *ei = find_exception(code); if ( ei != NULL ) { qstrncpy(buf, ei->name.c_str(), bufsize); return true; } qsnprintf(buf, bufsize, "%08X", code); return false; }
SLFUTURE_CONST char *SLerr_strerror (int err_code) { Exception_Type *e; if (err_code == 0) err_code = _pSLang_Error; if (-1 == _pSLerr_init ()) return "Unable to initialize SLerr module"; if (NULL == (e = find_exception (Exception_Root, err_code))) return "Invalid/Unknown Error Code"; return e->description; }
static int is_exception_ancestor (int a, int b) { Exception_Type *e; if (a == b) return 1; if (NULL == (e = find_exception (Exception_Root, a))) return 0; while (e->parent != NULL) { e = e->parent; if (e->error_code == b) return 1; } return 0; }
int SLerr_new_exception (int baseclass, SLFUTURE_CONST char *name, SLFUTURE_CONST char *descript) { Exception_Type *base; Exception_Type *e; if (-1 == _pSLerr_init ()) return -1; base = find_exception (Exception_Root, baseclass); if (base == NULL) { _pSLang_verror (SL_InvalidParm_Error, "Base class for new exception not found"); return -1; } e = (Exception_Type *) SLcalloc (1, sizeof (Exception_Type)); if (e == NULL) return -1; if ((NULL == (e->name = SLang_create_slstring (name))) || (NULL == (e->description = SLang_create_slstring (descript)))) { free_this_exception (e); return -1; } e->error_code = Next_Exception_Code; if ((_pSLerr_New_Exception_Hook != NULL) && (-1 == (*_pSLerr_New_Exception_Hook) (e->name, e->description, e->error_code))) { free_this_exception (e); return -1; } e->parent = base; e->next = base->subclasses; base->subclasses = e; Next_Exception_Code++; return e->error_code; }
static Exception_Type *find_exception (Exception_Type *root, int error_code) { Exception_Type *e; while (root != NULL) { if (error_code == root->error_code) return root; if (root->subclasses != NULL) { e = find_exception (root->subclasses, error_code); if (e != NULL) return e; } root = root->next; } return root; }