Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tany3/e4344e2fd1b187d232f766835018fafe to your computer and use it in GitHub Desktop.
Save tany3/e4344e2fd1b187d232f766835018fafe to your computer and use it in GitHub Desktop.
例外をキャッチして再スローするとスタックトレースが途切れるヤツ
// https://msdn.microsoft.com/ja-jp/library/ms229005(v=vs.100).aspx
// 例外をキャッチして再スローする場合は、空の throw を使用してください。 例外呼び出し履歴を保持するには、これが最善の方法です。
void Main()
{
try
{
DoSomething1();
}
catch (Exception ex)
{
ex.Dump();
}
}
// Define other methods and classes here
void DoSomething1()
{
try
{
DoSomething2();
}
catch (Exception ex)
{
ex.Dump();
throw;
}
}
void DoSomething2()
{
ThrowException();
}
void ThrowException()
{
var ex = new Exception("hoge");
ex.Data.Add("key1", "value1");
throw ex;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment