Coder Social home page Coder Social logo

exceptions's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

exceptions's Issues

try statement inside catch

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.

Also hook RET opcodes

Currently it only hooks RETN opcodes. The only place the RET opcodes are is in the very rare seemingly unsupported entry function.

Catch runtime errors

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

Create tests

Things to test

  • Nesting
  • Recursive nesting
  • Stack and heap integrity
  • Huge gamemodes
  • YSI
  • CallLocalFunction and CallRemoteFunction
  • Performance

Compiler options

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.

CallLocalFunction

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 errors in catch/finally

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.