Created
April 12, 2018 12:05
-
-
Save tany3/e4344e2fd1b187d232f766835018fafe to your computer and use it in GitHub Desktop.
例外をキャッチして再スローするとスタックトレースが途切れるヤツ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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