Patch that adds Line Number and Column Number to the exceptions thrown by V8Sharp

Jul 7, 2010 at 10:57 PM

This patch let's you get vital information like Line Number and Column number from the exceptions thrown when you call Compile or Execute()

Here's an example:

 

 

        private void compileButton_Click(object sender, EventArgs e)
        {
            try
            {
                V8Script script = _engine.Compile(_default_ai);
                var ret = _engine.Execute(script);
            }
            catch (V8Exception err) // Code failed to run
            {
                string log = String.Format("Line {0}, Col {1}: {2} \"{3}\"", err.LineNumber, err.StartColumn, err.Message, err.SourceLine);
                Log.TraceError("V8Executer", log);
                MessageBox.Show("The AI script failed to run. Please check your script for syntax errors\nFalling back on previous script.\n\nErrors:\n" + log, "AI Compile Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (V8ScriptException ex) // Code failed to compile
            {
                StringBuilder errors = new StringBuilder();
                // Get a list of exceptions because IList doesn't have a public enumerator
                var list = ex.Exceptions as List<V8Exception>;
                foreach (V8Exception err in list)
                {

                    string log = String.Format("Line {0}, Col {1}: {2} \"{3}\"", err.LineNumber, err.StartColumn, err.Message, err.SourceLine);
                    errors.AppendLine(err.Message);
                    Log.TraceError("V8Compiler", log);
                }
                MessageBox.Show("The AI script failed to compile. Please check your script for syntax errors\nFalling back on previous script.\n\nErrors:\n" + errors.ToString(), "AI Compile Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

 

 

http://rapidshare.com/files/405587122/v8sharp_error_patch.zip