Exception handling before and after main

后端 未结 4 856
再見小時候
再見小時候 2021-02-15 17:52

Is it possible to handle exceptions in these scenarios:

  1. thrown from constructor before entering main()
  2. thrown from destructor after leaving main()
4条回答
  •  耶瑟儿~
    2021-02-15 17:57

    Short answer: no.

    Any global object that throws an exception in its constructor will cause an unhandled exception (that is, terminate be called).

    Any class that throws an exception in its destructor is a broken class.

    Using the singleton pattern rather than globals will give you more options.

提交回复
热议问题