Skip to content

Instantly share code, notes, and snippets.

@zhangz
Created June 18, 2011 13:55
Show Gist options
  • Save zhangz/1033120 to your computer and use it in GitHub Desktop.
Save zhangz/1033120 to your computer and use it in GitHub Desktop.
ExceptionTest
class ExceptionTest
{
long maxLevel = 20;
static void Main(string[] args)
{
ExceptionTest test = new ExceptionTest();
int count = 10000;
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < count; i++)
{
try
{
test.doTest(2, 0);
}
catch (Exception ex)
{
//string st = ex.StackTrace;
}
}
sw.Stop();
long elapsedMilliseconds = sw.ElapsedMilliseconds;
Console.WriteLine(String.Format("Total time for invocation: {0}", elapsedMilliseconds));
}
public void doTest(int i, int level)
{
if (level < maxLevel)
{
try
{
doTest(i, ++level);
}
catch (Exception ex)
{
//string st = ex.StackTrace;
throw new ApplicationException("level < maxLevel", ex);
}
}
else
{
if (i > 1)
throw new ApplicationException("level > maxLevel");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment