The Labs \ Source Viewer \ SSCLI \ Microsoft.JScript \ ErrorObject

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. namespace Microsoft.JScript
  16. {
  17.    
  18.     using System;
  19.     using System.Runtime.InteropServices;
  20.    
  21.     public class ErrorObject : JSObject
  22.     {
  23.         public object message;
  24.         public object number;
  25.         public object description;
  26.         internal object exception;
  27.        
  28.         internal ErrorObject(ErrorPrototype parent, object[] args) : base(parent)
  29.         {
  30.             this.exception = null;
  31.             this.description = "";
  32.             this.number = 0;
  33.             if (args.Length == 1)
  34.                 if (args[0] == null || Convert.IsPrimitiveNumericType(args[0].GetType()))
  35.                     this.number = Convert.ToNumber(args[0]);
  36.                 else
  37.                     this.description = Convert.ToString(args[0]);
  38.             else if (args.Length > 1) {
  39.                 this.number = Convert.ToNumber(args[0]);
  40.                 this.description = Convert.ToString(args[1]);
  41.             }
  42.             this.message = this.description;
  43.             this.noExpando = false;
  44.         }
  45.        
  46.         internal ErrorObject(ErrorPrototype parent, object e) : base(parent)
  47.         {
  48.             this.exception = e;
  49.             this.number = unchecked((int)(2148139008u + (int)JSError.UncaughtException));
  50.             if (e is Exception) {
  51.                 if (e is JScriptException)
  52.                     this.number = ((JScriptException)e).Number;
  53.                 else if (e is ExternalException)
  54.                     this.number = ((ExternalException)e).ErrorCode;
  55.                 this.description = ((Exception)e).Message;
  56.                 if (((string)this.description).Length == 0)
  57.                     this.description = e.GetType().FullName;
  58.             }
  59.             this.message = this.description;
  60.             this.noExpando = false;
  61.         }
  62.        
  63.         internal override string GetClassName()
  64.         {
  65.             return "Error";
  66.         }
  67.        
  68.         internal string Message {
  69.             get { return Convert.ToString(this.message); }
  70.         }
  71.        
  72.         public static explicit operator Exception(ErrorObject err)
  73.         {
  74.             return err.exception as Exception;
  75.         }
  76.        
  77.         public static Exception ToException(ErrorObject err)
  78.         {
  79.             return (Exception)err;
  80.         }
  81.     }
  82. }

Developer Fusion