2004-08-05 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Thu, 5 Aug 2004 11:42:26 +0000 (11:42 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Thu, 5 Aug 2004 11:42:26 +0000 (11:42 -0000)
* StackTrace.cs: Added missing exceptions. Added globalization. Now
using StringBuilder in ToString (fusioned FrameToString).

svn path=/trunk/mcs/; revision=31921

mcs/class/corlib/System.Diagnostics/ChangeLog
mcs/class/corlib/System.Diagnostics/StackTrace.cs

index 7e18111d957c4baae7d3e2405efb4b3a096f2bec..51535802545f46dba1d902e7c36c7df1976cf0d0 100644 (file)
@@ -1,3 +1,8 @@
+2004-08-05  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * StackTrace.cs: Added missing exceptions. Added globalization. Now 
+       using StringBuilder in ToString (fusioned FrameToString).
+
 2004-08-04  Sebastien Pouliot  <sebastien@ximian.com>
 
        * StackTrace.cs: Implemented GetFrames as public virtual for NET_2_0
index 20af9da92ed08e760b36d3c0637ecbdc6453da1d..22ff8fcfb69f5c46b04422502a45eaf63c8b2bac 100644 (file)
@@ -6,9 +6,6 @@
 //      Dietmar Maurer (dietmar@ximian.com)
 //
 // (C) 2001
-//
-
-//
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 //
 
 using System;
+using System.Collections;
+using System.Globalization;
 using System.Reflection;
-using System.Threading;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
-using System.Collections;
+using System.Text;
+using System.Threading;
 
 namespace System.Diagnostics {
 
@@ -70,6 +69,9 @@ namespace System.Diagnostics {
 
                void init_frames (int skipFrames, bool needFileInfo)
                {
+                       if (skipFrames < 0)
+                               throw new ArgumentOutOfRangeException ("< 0", "skipFrames");
+
                        StackFrame sf;
                        ArrayList al = new ArrayList ();
 
@@ -89,22 +91,27 @@ namespace System.Diagnostics {
                extern static StackFrame [] get_trace (Exception e, int skipFrames, bool needFileInfo);
 
                public StackTrace (Exception e)
+                       : this (e, METHODS_TO_SKIP, false)
                {
-                       frames = get_trace (e, METHODS_TO_SKIP, false);
                }
 
                public StackTrace (Exception e, bool needFileInfo)
+                       : this (e, METHODS_TO_SKIP, needFileInfo)
                {
-                       frames = get_trace (e, METHODS_TO_SKIP, needFileInfo);
                }
 
                public StackTrace (Exception e, int skipFrames)
+                       : this (e, skipFrames, false)
                {
-                       frames = get_trace (e, skipFrames, false);
                }
 
                public StackTrace (Exception e, int skipFrames, bool needFileInfo)
                {
+                       if (e == null)
+                               throw new ArgumentNullException ("e");
+                       if (skipFrames < 0)
+                               throw new ArgumentOutOfRangeException ("< 0", "skipFrames");
+
                        frames = get_trace (e, skipFrames, needFileInfo);
                }
 
@@ -117,14 +124,14 @@ namespace System.Diagnostics {
                [MonoTODO]
                public StackTrace (Thread targetThread, bool needFileInfo)
                {
-                       throw new NotImplementedException();
+                       throw new NotImplementedException ();
                }
 
                public virtual int FrameCount {
                        get {
                                return (frames == null) ? 0 : frames.Length;
                        }
-               }            
+               }
 
                public virtual StackFrame GetFrame (int index)
                {
@@ -139,7 +146,7 @@ namespace System.Diagnostics {
                [ComVisibleAttribute (false)]
                public virtual
 #else
-               // used for CAS implementation
+               // used for CAS implementation (before Fx 2.0)
                internal
 #endif
                StackFrame[] GetFrames ()
@@ -149,13 +156,24 @@ namespace System.Diagnostics {
 
                public override string ToString ()
                {
-                       string result = "";
+                       string newline = String.Format ("{0}\t {1} ", Environment.NewLine, Locale.GetText ("at"));
+                       string unknown = Locale.GetText ("<unknown method>");
+                       StringBuilder sb = new StringBuilder ();
                        for (int i = 0; i < FrameCount; i++) {
                                StackFrame frame = GetFrame (i);
-                               result += "\n\tat " + FrameToString (frame);
+                               sb.Append (newline);
+                               MethodBase method = frame.GetMethod ();
+                               if (method != null) {
+                                       // Method information available
+                                       sb.AppendFormat ("{0}.{1} ()", method.DeclaringType.FullName, method.Name);
+                               }
+                               else {
+                                       // Method information not available
+                                       sb.Append (unknown);
+                               }
                        }
 
-                       return result;
+                       return sb.ToString ();
                }
 
                //
@@ -188,19 +206,5 @@ namespace System.Diagnostics {
                        return FrameCount;
                }
 #endif
-
-               private static string FrameToString (StackFrame frame)
-               {
-                       MethodBase method = frame.GetMethod ();
-                       if (method != null) {
-                               // Method information available
-                               return  method.DeclaringType.FullName
-                                       + "." + method.Name + "()";
-                       }
-                       else {
-                               // Method information not available
-                               return "<unknown method>";
-                       }
-               }
        }
 }