M
Mike Schilling
Instances of SystemOutOfMemoryException do not contain a stack trace. Easy
test to verify this:
class OOM
{
public static void Main() {
try {
Object[, ] arr = new Object[100000000, 10000000];
} catch (Exception ex) {
dumpEx(ex);
}
}
private static void dumpEx(Exception ex) {
Console.WriteLine("Exception occurred");
Console.WriteLine(ex);
String s = ex.StackTrace;
if (s == null)
Console.WriteLine("Stack trace is null");
else
Console.WriteLine("StackTrace length is " + s.Length);
}
}
Output:
Exception occurred
System.OutOfMemoryException: Exception of type System.OutOfMemoryException
was thrown.
Stack trace is null
This makes debugging these exceptions tricky, to say the least. I wound up
having to track down where the exception was being generated with
WriteLines. I know that you can trap these is Visual Studio as well, but
this one was touchy (it turned out to be a synchronization problem) and the
performance degradation from running an ASP.NET program inside Visual Studio
made it stop happening. Two questions:
1. Are there any tricks that I'm missing for debugging these more
effectively?
2. Can we expect to see stack traces in some future release?
test to verify this:
class OOM
{
public static void Main() {
try {
Object[, ] arr = new Object[100000000, 10000000];
} catch (Exception ex) {
dumpEx(ex);
}
}
private static void dumpEx(Exception ex) {
Console.WriteLine("Exception occurred");
Console.WriteLine(ex);
String s = ex.StackTrace;
if (s == null)
Console.WriteLine("Stack trace is null");
else
Console.WriteLine("StackTrace length is " + s.Length);
}
}
Output:
Exception occurred
System.OutOfMemoryException: Exception of type System.OutOfMemoryException
was thrown.
Stack trace is null
This makes debugging these exceptions tricky, to say the least. I wound up
having to track down where the exception was being generated with
WriteLines. I know that you can trap these is Visual Studio as well, but
this one was touchy (it turned out to be a synchronization problem) and the
performance degradation from running an ASP.NET program inside Visual Studio
made it stop happening. Two questions:
1. Are there any tricks that I'm missing for debugging these more
effectively?
2. Can we expect to see stack traces in some future release?