New tests.
[mono.git] / mcs / class / corlib / System / Exception.cs
index c3427aded42a2aa6c2c6e5d3193f1dadb96357e7..b4a2f1ee665cf1c2faf13efd5797fdaf1548e158 100644 (file)
@@ -40,17 +40,10 @@ using System.Security.Permissions;
 namespace System
 {
        [Serializable]
-#if NET_2_0
        [ComVisible(true)]
        [ComDefaultInterface (typeof (_Exception))]
        [ClassInterface (ClassInterfaceType.None)]
-#else
-       [ClassInterface (ClassInterfaceType.AutoDual)]
-#endif
-       public class Exception : ISerializable 
-#if NET_2_0
-       , _Exception
-#endif
+       public class Exception : ISerializable, _Exception
        {
 #pragma warning disable 169, 649
                #region Sync with object-internals.h
@@ -62,7 +55,8 @@ namespace System
                string help_link;
                string class_name;
                string stack_trace;
-               string remote_stack_trace;
+               // formerly known as remote_stack_trace (see #425512):
+               string _remoteStackTraceString;
                int remote_stack_index;
                internal int hresult = -2146233088;
                string source;
@@ -88,20 +82,17 @@ namespace System
                        message             = info.GetString ("Message");
                        help_link           = info.GetString ("HelpURL");
                        stack_trace         = info.GetString ("StackTraceString");
-                       remote_stack_trace  = info.GetString ("RemoteStackTraceString");
+                       _remoteStackTraceString  = info.GetString ("RemoteStackTraceString");
                        remote_stack_index  = info.GetInt32  ("RemoteStackIndex");
                        hresult             = info.GetInt32  ("HResult");
                        source              = info.GetString ("Source");
                        inner_exception     = (Exception) info.GetValue ("InnerException", typeof (Exception));
 
-#if NET_2_0
                        try {
                                _data = (IDictionary) info.GetValue ("Data", typeof (IDictionary));
                        } catch (SerializationException) {
                                // member did not exist in .NET 1.x
                        }
-#endif
-
                }
 
                public Exception (string message, Exception innerException)
@@ -145,11 +136,7 @@ namespace System
                public virtual string Message {
                        get {
                                if (message == null)
-#if NET_2_0
                                        message = string.Format (Locale.GetText ("Exception of type '{0}' was thrown."),
-#else
-                                       message = string.Format (Locale.GetText ("Exception of type {0} was thrown."),
-#endif
                                                ClassName);
 
                                return message;
@@ -157,9 +144,6 @@ namespace System
                }
 
                public virtual string Source {
-#if ONLY_1_1
-                       [ReflectionPermission (SecurityAction.Assert, TypeInformation = true)]
-#endif
                        get {
                                if (source == null) {
                                        StackTrace st = new StackTrace (this, true);
@@ -218,10 +202,9 @@ namespace System
                                                        else
                                                                sb.AppendFormat (" [0x{0:x5}] ", frame.GetILOffset ());
 
-                                                       string fileName = frame.GetFileName ();
-                                                       if (fileName != null)
-                                                               sb.AppendFormat ("in {0}:{1} ", fileName, frame.GetFileLineNumber ());
-                                                       }
+                                                       sb.AppendFormat ("in {0}:{1} ", frame.GetSecureFileName (), 
+                                                               frame.GetFileLineNumber ());
+                                               }
                                        }
                                        stack_trace = sb.ToString ();
                                }
@@ -231,9 +214,6 @@ namespace System
                }
 
                public MethodBase TargetSite {
-#if ONLY_1_1
-                       [ReflectionPermission (SecurityAction.Demand, TypeInformation = true)]
-#endif
                        get {
                                StackTrace st = new StackTrace (this, true);
                                if (st.FrameCount > 0)
@@ -243,7 +223,6 @@ namespace System
                        }
                }
 
-#if NET_2_0
                public virtual IDictionary Data {
                        get {
                                if (_data == null) {
@@ -253,7 +232,6 @@ namespace System
                                return _data;
                        }
                }
-#endif
 
                public virtual Exception GetBaseException ()
                {
@@ -270,9 +248,6 @@ namespace System
                        return this;
                }
 
-#if ONLY_1_1
-               [ReflectionPermission (SecurityAction.Assert, TypeInformation = true)]
-#endif
                [SecurityPermission (SecurityAction.LinkDemand, SerializationFormatter = true)]
                public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
                {
@@ -284,26 +259,25 @@ namespace System
                        info.AddValue ("InnerException", inner_exception);
                        info.AddValue ("HelpURL", help_link);
                        info.AddValue ("StackTraceString", StackTrace);
-                       info.AddValue ("RemoteStackTraceString", remote_stack_trace);
+                       info.AddValue ("RemoteStackTraceString", _remoteStackTraceString);
                        info.AddValue ("RemoteStackIndex", remote_stack_index);
                        info.AddValue ("HResult", hresult);
+#if !MOONLIGHT
                        info.AddValue ("Source", Source);
+#else
+                       info.AddValue ("Source", null);
+#endif
                        info.AddValue ("ExceptionMethod", null);
-#if NET_2_0
                        info.AddValue ("Data", _data, typeof (IDictionary));
-#endif
                }
 
-#if ONLY_1_1
-               [ReflectionPermission (SecurityAction.Assert, TypeInformation = true)]
-#endif
                public override string ToString ()
                {
                        System.Text.StringBuilder result = new System.Text.StringBuilder (ClassName);
                        result.Append (": ").Append (Message);
 
-                       if (null != remote_stack_trace)
-                               result.Append (remote_stack_trace);
+                       if (null != _remoteStackTraceString)
+                               result.Append (_remoteStackTraceString);
                                
                        if (inner_exception != null) 
                        {
@@ -324,7 +298,7 @@ namespace System
                                Locale.GetText ("{1}{0}{0}Exception rethrown at [{2}]: {0}");
                        string tmp = String.Format (message, Environment.NewLine, StackTrace, remote_stack_index);
 
-                       remote_stack_trace = tmp;
+                       _remoteStackTraceString = tmp;
                        remote_stack_index++;
 
                        stack_trace = null;
@@ -339,7 +313,6 @@ namespace System
                        sb.Append (".");
                        sb.Append (mi.Name);
 
-#if NET_2_0 || BOOTSTRAP_NET_2_0
                        if (mi.IsGenericMethod) {
                                Type[] gen_params = mi.GetGenericArguments ();
                                sb.Append ("[");
@@ -350,7 +323,7 @@ namespace System
                                }
                                sb.Append ("]");
                        }
-#endif
+
                        sb.Append (" (");
                        for (int i = 0; i < p.Length; ++i) {
                                if (i > 0)
@@ -369,7 +342,6 @@ namespace System
                        sb.Append (")");
                }
 
-#if NET_2_0
                //
                // The documentation states that this is available in 1.x,
                // but it was not available (MemberRefing this would fail)
@@ -380,6 +352,5 @@ namespace System
                {
                        return base.GetType ();
                }
-#endif
        }
 }