According to MSDN , Environment.StackTrace can raise an ArgumentOutOfRangeException , but I don't understand how this is possible.
Environment.cs StackTrace ( source )
public static String StackTrace { [System.Security.SecuritySafeCritical] get { Contract.Ensures(Contract.Result<String>() != null); new EnvironmentPermission(PermissionState.Unrestricted).Demand(); return GetStackTrace(null, true); } }
Calls GetStackTrace(Exception, bool) , where Exception is null.
Environment.cs GetStackTrace(Exception, bool) ( source ) (comments are deleted, they are irrelevant)
internal static String GetStackTrace(Exception e, bool needFileInfo) { StackTrace st; if (e == null) st = new StackTrace(needFileInfo); else st = new StackTrace(e, needFileInfo); return st.ToString( System.Diagnostics.StackTrace.TraceFormat.Normal ); }
The above method can call two StackTrace constructors, StackTrace(bool) and StackTrace(Exception, bool) .
We know from the first call that if this method is achieved by calling Environment.StackTrace , then StackTrace(bool) guaranteed to be called.
But StackTrace(bool) does not throw any exceptions according to MSDN . Another possible call to the StackTrace(Exception, bool) constructor StackTrace(Exception, bool) ( MSDN ) throws an exception, but it is ArgumentNullException not ArgumentOutOfRangeException . I do not see any other method calls made in the code that would throw an ArgumentOutOfRangeException .
So what am I missing? Is it possible for Environment.StackTrace to throw an exception, and if so, how?