Is it possible to find the function and / or line number that caused the error in ActionScript 3.0 without using debug mode?

I am currently trying to implement an automated error reporter for a Flex application and would like to return error messages to the server along with the function / line number that caused the error. Essentially, I'm trying to get getStackTrace () information without in debug mode, because most users of the application are unlikely to have a debug version of the flash player.

My current method uses the UncaughtErrorEvent handler to detect errors that occur in the application, but the error message returns only the type of error, not the location (which means it's useless). I tried to implement getStackTrace () myself using a name-grabber function such as

private function getFunctionName (callee:Function, parent:Object):String { for each ( var m:XML in describeType(parent)..method) { if ( this[ m.@name ] == callee) return m.@name ; } return "private function!"; } 

but this will only work because of arguments.callee, and therefore will not go through several levels of function calls (it will never exceed my error event listener).

So! Anyone have ideas on how to receive error information messages through the global error event handler?

EDIT . There seems to be some misunderstanding. I explicitly avoid getStackTrace () because it returns "null" if not in debug mode. Any solution using this feature is something that I specifically avoid.

+6
source share
2 answers

Just noticed the part "I do not want to use debug". Well, this is not an option, since the non-debug version of Flash does not have a clue about stack tracing at all. Sucks, right?


Not relevant, but still cool.

The rest is for the debug player.

This is part of my personal debugging class (oddly enough, it is added to every single project I'm working on). It returns a string representing the index on the passed stack — the class and method name. When you have it, the line number is trivial.

  /** * Returns the function name of whatever called this function (and whatever called that)... */ public static function getCaller( index:int = 0 ):String { try { throw new Error('pass'); } catch (e:Error) { var arr:Array = String(e.getStackTrace()).split("\t"); var value:String = arr[3 + index]; // This pattern matches a standard function. var re:RegExp = /^at (.*?)\/(.*?)\(\)/ ; var owner:Array = re.exec(value); try { var cref:Array = owner[1].split('::'); return cref[ 1 ] + "." + owner[2]; } catch( e:Error ) { try { re = /^at (.*?)\(\)/; // constructor. owner = re.exec(value); var tmp:Array = owner[1].split('::'); var cName:String = tmp.join('.'); return cName; } catch( error:Error ) { } } } return "No caller could be found."; } 

As a side note: this is incorrectly configured to handle the event model - sometimes events are either not callers or a very strange alternative syntax.

+3
source

You do not need to throw an error to get a stack trace.

 var myError:Error = new Error(); var theStack:String = myError.getStackTrace(); 

good reference to the Error class


[EDIT]
No, after reading my help, getStackTrace () is only available in debug versions of the flash player.
So it looks like you are stuck with what you are doing now.

+2
source

Source: https://habr.com/ru/post/891588/


All Articles