oscar-broman / exceptions Goto Github PK
View Code? Open in Web Editor NEWExceptions for Pawn (SA-MP).
Home Page: http://forum.sa-mp.com/showthread.php?t=425063
Exceptions for Pawn (SA-MP).
Home Page: http://forum.sa-mp.com/showthread.php?t=425063
This doesn't work unless the try statement is within a function call. Will require a bit of refactoring. Probably won't happen unless increased demand.
Currently it only hooks RETN
opcodes. The only place the RET
opcodes are is in the very rare seemingly unsupported entry
function.
crashdetect can report runtime errors to a public function - hook this function and use it to throw exceptions.
One of the problems with doing this is the outer public function will return 0 before OnRuntimeError
, which makes it impossible to gracefully handle runtime errors in callbacks such as OnPlayerUpdate
and OnPlayerCommandText
.
Old code for this:
forward OnRuntimeError(code);
public OnRuntimeError(code) {
if (s_UncaughtException) {
return;
}
static const sc_messages[28][54] = {
/* AMX_ERR_NONE */ "None",
/* AMX_ERR_EXIT */ "Forced exit",
/* AMX_ERR_ASSERT */ "Assertion failed",
/* AMX_ERR_STACKERR */ "Stack/heap collision (insufficient stack size)",
/* AMX_ERR_BOUNDS */ "Array 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 (valid) native function callback",
/* AMX_ERR_NATIVE */ "Native function failed",
/* AMX_ERR_DIVIDE */ "Divide by zero",
/* AMX_ERR_SLEEP */ "sleep mode",
/* 13 */ "reserved",
/* 14 */ "reserved",
/* 15 */ "reserved",
/* AMX_ERR_MEMORY */ "Out of memory",
/* AMX_ERR_FORMAT */ "Invalid/unsupported P-code file format",
/* AMX_ERR_VERSION */ "File is for a newer version of the AMX",
/* AMX_ERR_NOTFOUND */ "File or function is 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)"
};
static msg[128];
if (0 <= code < sizeof(sc_messages)) {
format(msg, sizeof(msg), "runtime error %d: %s", code, sc_messages[code]);
} else {
format(msg, sizeof(msg), "runtime error %d", code);
}
if (funcidx(!"Exceptions_OnRuntimeError") != -1) {
CallLocalFunction(!"Exceptions_OnRuntimeError", !"i", code);
}
ThrowError(msg);
}
#if defined _ALS_OnRuntimeError
#undef OnRuntimeError
#else
#define _ALS_OnRuntimeError
#endif
#define OnRuntimeError Exceptions_OnRuntimeError
Placing finally before catch and similar. Just display an error and exit.
CallLocalFunction
and CallRemoteFunction
Make a batch file that will compile the tests with the following flag combinations:
-O0 -d0
-O0 -d1
-O0 -d2
-O1 -d0
-O1 -d1
-O1 -d2
Be sure to run on both Linux and Windows.
Throwing an error inside a public function invoked by CallLocalFunction
doesn't work. I suspect it's because the public function should be returning outside of the AMX, which it never does when ThrowError
is invoked.
Throwing an exception in catch
will cause it to skip finally
, which it shouldn't.
Throwing an exception in finally
doesn't pop the context, which it should.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.