How to catch an unhandled exception in Windows Azure (Worker) Role

前端 未结 2 688
旧时难觅i
旧时难觅i 2020-12-29 13:31

I\'m trying to catch all unhandled exceptions in my worker role. I tried putting a try-catch block into the Run() method (as suggested

相关标签:
2条回答
  • 2020-12-29 14:04

    The catch will catch all exceptions.

    You are throwing it again so that one will not be caught.

    Also you are logging, but logs are not turned on by default in Azure, since they cost.

    The other alternative is that there is no exception.

    0 讨论(0)
  • 2020-12-29 14:05

    As already updated in my question, here for completeness's sake as answer:

    Obviously it is like in a normal c# application: Just add a handler to the UnhandledException event like this

    AppDomain.CurrentDomain.UnhandledException +=
       new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    

    inside the OnStart() of the Role.

    0 讨论(0)
提交回复
热议问题