private static void OnUnhandledException(Exception ex)
{
+ if (CheckIgnorableError(ex))
+ return;
+
if (MyCommon.ExceptionOut(ex))
{
Application.Exit();
}
}
+ /// <summary>
+ /// 無視しても問題のない既知の例外であれば true を返す
+ /// </summary>
+ private static bool CheckIgnorableError(Exception ex)
+ {
+#if DEBUG
+ return false;
+#else
+ if (ex is AggregateException aggregated)
+ {
+ if (aggregated.InnerExceptions.Count != 1)
+ return false;
+
+ ex = aggregated.InnerExceptions.Single();
+ }
+
+ switch (ex)
+ {
+ case System.Net.WebException webEx:
+ // SSL/TLS のネゴシエーションに失敗した場合に発生する。なぜかキャッチできない例外
+ // https://osdn.net/ticket/browse.php?group_id=6526&tid=37432
+ if (webEx.Status == System.Net.WebExceptionStatus.SecureChannelFailure)
+ return true;
+ break;
+ case System.Threading.Tasks.TaskCanceledException cancelEx:
+ // ton.twitter.com の画像でタイムアウトした場合、try-catch で例外がキャッチできない
+ // https://osdn.net/ticket/browse.php?group_id=6526&tid=37433
+ var stackTrace = new System.Diagnostics.StackTrace(cancelEx);
+ var lastFrameMethod = stackTrace.GetFrame(stackTrace.FrameCount - 1).GetMethod();
+ if (lastFrameMethod.ReflectedType == typeof(Connection.TwitterApiConnection) &&
+ lastFrameMethod.Name == nameof(Connection.TwitterApiConnection.GetStreamAsync))
+ return true;
+ break;
+ }
+
+ return false;
+#endif
+ }
+
public static void InitCulture()
{
var currentCulture = CultureInfo.CurrentUICulture;