actionscript-3apache-flexmacros

ActionScript 3.0 compiler macro to create string of current AS file and code Line?


i'd like to do something like this:

try{
    operationThatMayFail();
}
catch(e:Error){
    handleError();
    MyLogFileLogger.writeEntry("Error ocurred in file " + CURRENT_AS_FILE + " on line: " + CURRENT_LINE);
}

of course i could hardcode that - but if I then change something about the as file, the linenumbers won't be correct anymore, or maybe i rename the as file and so on. It'd be great to be able to create that string somehow using compiler directives.

Is this Possible in an AIR application created with ActionScript 3.0?


Solution

  • You should look up the Error class caught in the exception. You'll want to do this:

    try{
        operationThatMayFail();
    }
    catch(e:Error){
        handleError();
        MyLogFileLogger.writeEntry(e.getStackTrace());
    }