Does it make sense to catch ThreadAbortException and perform no action?

后端 未结 5 2244
旧时难觅i
旧时难觅i 2021-02-20 01:31
catch (ThreadAbortException)
{ }
catch (Exception ex)
{
    TraceManager.TraceException(ex,
                                (int)ErrorCode.GENERIC_EXCEPTION,
                    


        
5条回答
  •  一向
    一向 (楼主)
    2021-02-20 01:44

    Calling Thread.Abort on a thread effectively sets a flag which will cause a ThreadAbortException to be thrown any time code isn't processing that exception nor associated finally blocks. Catching the exception without calling Thread.ResetAbort() will simply result in the runtime throwing another ThreadAbortException at its next opportunity. Such behavior is not completely meaningless, however, since it will cause all inner finally blocks to run to completion before the exception can be seen by outer exception-filter blocks. Whether or not that is a good thing will depend upon the application.

提交回复
热议问题