using System; using Jint.Native; using Jint.Native.Error; namespace Jint.Runtime { public class JavaScriptException : Exception { private readonly JsValue _errorObject; public JavaScriptException(ErrorConstructor errorConstructor) : base("") { _errorObject = errorConstructor.Construct(Arguments.Empty); } public JavaScriptException(ErrorConstructor errorConstructor, string message) : base(message) { _errorObject = errorConstructor.Construct(new JsValue[] { message }); } public JavaScriptException(JsValue error) : base(GetErrorMessage(error)) { _errorObject = error; } private static string GetErrorMessage(JsValue error) { if (error.IsObject()) { var oi = error.AsObject(); var message = oi.Get("message").AsString(); return message; } else return string.Empty; } public JsValue Error { get { return _errorObject; } } public override string ToString() { return _errorObject.ToString(); } } }