Static Constructor and Exceptions

北慕城南 提交于 2019-12-12 08:45:12

问题


What happen if a static constructor throws and exception and it is not handled?

Will it remain till the application domain alive?


回答1:


An unhandled exception in a static constructor, will be wrapped in a TypeInitializationException. If you're on .NET 2 or newer an unhandled exception will terminate the process.




回答2:


The exception will propagate and if it is not caught somewhere like for example a global exception handler it will simply kill the application domain.




回答3:


if an Exception happens in a static Constructor and you don't catch it, then you will never use its static Method , filed or property, even cann't create its instance, otherwise it will cause a TypeInitializationException.



来源:https://stackoverflow.com/questions/4579016/static-constructor-and-exceptions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!