Esempio n. 1
0
        public void print_exception(IScriptLogger logger, LogLevel logLevel, string title)
        {
            var ex = JSApi.JS_GetException(this);

            try
            {
                if (logger != null)
                {
                    var err_fileName   = JSApi.JS_GetProperty(this, ex, JSApi.JS_ATOM_fileName);
                    var err_lineNumber = JSApi.JS_GetProperty(this, ex, JSApi.JS_ATOM_lineNumber);
                    var err_message    = JSApi.JS_GetProperty(this, ex, JSApi.JS_ATOM_message);
                    var err_stack      = JSApi.JS_GetProperty(this, ex, JSApi.JS_ATOM_stack);

                    try
                    {
                        var fileName   = err_fileName.IsNullish() ? "native" : JSApi.GetString(this, err_fileName);
                        var lineNumber = err_lineNumber.IsNullish() ? null : JSApi.GetString(this, err_lineNumber);
                        var message    = JSApi.GetString(this, err_message);
                        var stack      = JSApi.GetString(this, err_stack);

                        if (string.IsNullOrEmpty(lineNumber))
                        {
                            if (string.IsNullOrEmpty(stack))
                            {
                                logger.Write(logLevel, "[{0}] {1} {2}",
                                             fileName, title, message);
                            }
                            else
                            {
                                logger.Write(logLevel, "[{0}] {1} {2}\nJavascript stack:\n{3}",
                                             fileName, title, message, stack);
                            }
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(stack))
                            {
                                logger.Write(logLevel, "[{0}:{1}] {2} {3}",
                                             fileName, lineNumber, title, message);
                            }
                            else
                            {
                                logger.Write(logLevel, "[{0}:{1}] {2} {3}\nJavascript stack:\n{4}",
                                             fileName, lineNumber, title, message, stack);
                            }
                        }
                    }
                    finally
                    {
                        JSApi.JS_FreeValue(this, err_fileName);
                        JSApi.JS_FreeValue(this, err_lineNumber);
                        JSApi.JS_FreeValue(this, err_message);
                        JSApi.JS_FreeValue(this, err_stack);
                    }
                }
            }
            finally
            {
                JSApi.JS_FreeValue(this, ex);
            }
        }