Skip to content

Instantly share code, notes, and snippets.

@IS4Code
Created June 13, 2016 13:18
Show Gist options
  • Save IS4Code/79ee2d46ab4395230d9b46f0a908baa5 to your computer and use it in GitHub Desktop.
Save IS4Code/79ee2d46ab4395230d9b46f0a908baa5 to your computer and use it in GitHub Desktop.
/*
The MIT License (MIT)
Copyright (c) 2016 IllidanS4
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
//Documentation: http://forum.sa-mp.com/showthread.php?t=609511
//Version 1.0
/*
native raise(errcode);
native errormsg(errcode);
*/
enum
{
AMX_ERR_NONE,
AMX_ERR_EXIT, /* forced exit */
AMX_ERR_ASSERT, /* assertion failed */
AMX_ERR_STACKERR, /* stack/heap collision */
AMX_ERR_BOUNDS, /* index out of bounds */
AMX_ERR_MEMACCESS, /* invalid memory access */
AMX_ERR_INVINSTR, /* invalid instruction */
AMX_ERR_STACKLOW, /* stack underflow */
AMX_ERR_HEAPLOW, /* heap underflow */
AMX_ERR_CALLBACK, /* no callback, or invalid callback */
AMX_ERR_NATIVE, /* native function failed */
AMX_ERR_DIVIDE, /* divide by zero */
AMX_ERR_SLEEP, /* go into sleepmode - code can be restarted */
AMX_ERR_MEMORY = 16, /* out of memory */
AMX_ERR_FORMAT, /* invalid file format */
AMX_ERR_VERSION, /* file is for a newer version of the AMX */
AMX_ERR_NOTFOUND, /* function not found */
AMX_ERR_INDEX, /* invalid index parameter (bad entry point) */
AMX_ERR_DEBUG, /* debugger cannot run */
AMX_ERR_INIT, /* AMX not initialized (or doubly initialized) */
AMX_ERR_USERDATA, /* unable to set user data field (table full) */
AMX_ERR_INIT_JIT, /* cannot initialize the JIT */
AMX_ERR_PARAMS, /* parameter error */
AMX_ERR_DOMAIN, /* domain error, expression result does not fit in range */
AMX_ERR_GENERAL, /* general error (unknown or unspecific error) */
}
stock raise(errcode)
{
switch(errcode)
{
case AMX_ERR_NONE: {
#emit halt AMX_ERR_NONE
}
case AMX_ERR_EXIT: {
#emit halt AMX_ERR_EXIT
}
case AMX_ERR_ASSERT: {
#emit halt AMX_ERR_ASSERT
}
case AMX_ERR_STACKERR: {
#emit halt AMX_ERR_STACKERR
}
case AMX_ERR_BOUNDS: {
#emit halt AMX_ERR_BOUNDS
}
case AMX_ERR_MEMACCESS: {
#emit halt AMX_ERR_MEMACCESS
}
case AMX_ERR_INVINSTR: {
#emit halt AMX_ERR_INVINSTR
}
case AMX_ERR_STACKLOW: {
#emit halt AMX_ERR_STACKLOW
}
case AMX_ERR_HEAPLOW: {
#emit halt AMX_ERR_HEAPLOW
}
case AMX_ERR_CALLBACK: {
#emit halt AMX_ERR_CALLBACK
}
case AMX_ERR_NATIVE: {
#emit halt AMX_ERR_NATIVE
}
case AMX_ERR_DIVIDE: {
#emit halt AMX_ERR_DIVIDE
}
case AMX_ERR_SLEEP: {
#emit halt AMX_ERR_SLEEP
}
case 13: {
#emit halt 13
}
case 14: {
#emit halt 14
}
case 15: {
#emit halt 15
}
case AMX_ERR_MEMORY: {
#emit halt AMX_ERR_MEMORY
}
case AMX_ERR_FORMAT: {
#emit halt AMX_ERR_FORMAT
}
case AMX_ERR_VERSION: {
#emit halt AMX_ERR_VERSION
}
case AMX_ERR_NOTFOUND: {
#emit halt AMX_ERR_NOTFOUND
}
case AMX_ERR_INDEX: {
#emit halt AMX_ERR_INDEX
}
case AMX_ERR_DEBUG: {
#emit halt AMX_ERR_DEBUG
}
case AMX_ERR_INIT: {
#emit halt AMX_ERR_INIT
}
case AMX_ERR_USERDATA: {
#emit halt AMX_ERR_USERDATA
}
case AMX_ERR_INIT_JIT: {
#emit halt AMX_ERR_INIT_JIT
}
case AMX_ERR_PARAMS: {
#emit halt AMX_ERR_PARAMS
}
case AMX_ERR_DOMAIN: {
#emit halt AMX_ERR_DOMAIN
}
case AMX_ERR_GENERAL: {
#emit halt AMX_ERR_GENERAL
}
case 28: {
#emit halt 28
}
default: {
#emit halt 0xFFFFFFFF
}
}
}
static stock const errormsgs[][54] = {
"(none)",
"Forced exit",
"Assertion failed",
"Stack/heap collision (insufficient stack size)",
"Array index out of bounds",
"Invalid memory access",
"Invalid instruction",
"Stack underflow",
"Heap underflow",
"No (valid) native function callback",
"Native function failed",
"Divide by zero",
"(sleep mode)",
"(reserved)",
"(reserved)",
"(reserved)",
"Out of memory",
"Invalid/unsupported P-code file format",
"File is for a newer version of the AMX",
"File or function is not found",
"Invalid index parameter (bad entry point)",
"Debugger cannot run",
"AMX not initialized (or doubly initialized)",
"Unable to set user data field (table full)",
"Cannot initialize the JIT",
"Parameter error",
"Domain error, expression result does not fit in range",
"General error (unknown or unspecific error)",
"(unknown)"
};
stock errormsg(errcode)
{
if(0 <= errcode < sizeof(errormsgs))
{
return errormsgs[errcode];
}else{
return errormsgs[sizeof(errormsgs)-1];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment