According to MSDN, Environment.StackTrace
can throw 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 removed, 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 has the potential to call two constructors of StackTrace
, StackTrace(bool)
and StackTrace(Exception, bool)
.
We know from the first call that if this method is reached via the Environment.StackTrace
call then StackTrace(bool)
is guaranteed to be called.
But StackTrace(bool)
doesn't throw any exceptions according to MSDN. The other possible constructor call, StackTrace(Exception, bool)
(MSDN) does throw an exception, but it's ArgumentNullException
not ArgumentOutOfRangeException
. I don't see any other method calls made in the code that would throw ArgumentOutOfRangeException
.
So what am I missing? Is it actually possible for Environment.StackTrace
to throw an exception and if so how?
Retrieving the property value in fact shouldn't throw an exception. We've removed the exception information from the documentation for the Environment.StackTrace property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With