How can I get stacktrace for Adobe AIR global runtime errors in non-debug mode?

不羁岁月 提交于 2020-01-04 14:31:13

问题


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. :)

  1. 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 );
    }
    
  2. 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" );
    }
    
  3. Add additional compiler argument: -compiler.verbose-stacktraces=true

  4. Create the release build.
  5. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!