问题
The new version AIR gives us the ability to globally capture run time errors and handle them. The problem is that it doesn't have the stacktrace or any helpful information about the error other than the error id and error message and name. For example it may tell me that a null pointer exception has happened but it will not tell me where or which method or anything. The debug version of the runtime gives us all of that but when the app is deployed to customers it is not running on the debug version so none of the useful information is available. I was wondering if this group has any suggestions on how to enable better logging of errors in an AIR app for better supportability of the product. Any suggestions?
回答1:
No way until new version of AIR supports it. It doesn't now because of performance issues, rendering global handler almost useless. I'm waiting for it too, because alternative is logging everything yourself, and this is very time consuming.
回答2:
I have a little hack to get line numbers too. :)
make a listener to get uncaught errors. I do it in my main class:
private function addedToStageHandler(event:Event):void { loaderInfo.uncaughtErrorEvents.addEventListener( UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler ); }
for example my listener with
error.getStackTrace()
:private function uncaughtErrorHandler( event:UncaughtErrorEvent ):void { var errorText:String; var stack:String; if( event.error is Error ) { errorText = (event.error as Error).message; stack = (event.error as Error).getStackTrace(); if(stack != null){ errorText += stack; } } else if( event.error is ErrorEvent ) { errorText = (event.error as ErrorEvent).text; } else { errorText = event.text; } event.preventDefault(); Alert.show( errorText + " " + event.error, "Error" ); }
Add additional compiler argument:
-compiler.verbose-stacktraces=true
- Create the release build.
- now the little hack: Mac: Go to the installation location where you have your .app file. Right click and choose show package content. Navigate to Contents ▸ Resources ▸ META-INF ▸ AIR. There you can find a file called hash. Duplicate the hash file and rename it to debug. Open the debug file with some text editor and remove the content. Done now you get the stack trace + line numbers. Windows: Browse to its install directory in a file explorer. Navigate to {app-folder}▸META-INF▸AIR▸. Here you can find a file called hash. Duplicate the hash file and rename it to debug. Open the debug file with some text editor and remove the content. Done now you get the stack trace + line numbers.
If you can't find the hash file, just create an empty file without file extension and call it debug.
Tested with Air 3.6!
回答3:
The compiler option:
compiler.verbose-stacktraces=true
should embed stack information even in a non-debug build.
回答4:
About the compiler option. I develop with IntelliJ IDEA 14. In my build options i have also "Generate debuggable SWF". Maybe thats the reason why its working. Check my attachment. Grettings
来源:https://stackoverflow.com/questions/4473059/how-can-i-get-stacktrace-for-adobe-air-global-runtime-errors-in-non-debug-mode