C# catch a stack overflow exception

前端 未结 9 1069
生来不讨喜
生来不讨喜 2020-11-22 09:12

I have a recursive call to a method that throws a stack overflow exception. The first call is surrounded by a try catch block but the exception is not caught.

Does

9条回答
  •  礼貌的吻别
    2020-11-22 09:50

    Starting with 2.0 a StackOverflow Exception can only be caught in the following circumstances.

    1. The CLR is being run in a hosted environment* where the host specifically allows for StackOverflow exceptions to be handled
    2. The stackoverflow exception is thrown by user code and not due to an actual stack overflow situation (Reference)

    *"hosted environment" as in "my code hosts CLR and I configure CLR's options" and not "my code runs on shared hosting"

提交回复
热议问题