Getting information about where c++ exceptions are thrown inside of catch block?

后端 未结 5 1517
误落风尘
误落风尘 2020-12-13 23:02

I\'ve got a c++ app that wraps large parts of code in try blocks. When I catch exceptions I can return the user to a stable state, which is nice. But I\'m not longer recei

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 23:31

    One trick that is compiler independent is to wrap the throw statement in a function. The function can perform other duties before throwing the exception, such as recording to a log file. It also makes a handy place to put a breakpoint. If you create a macro to call the function you can automatically include the __FILE__ and __LINE__ where the throw occurred.

提交回复
热议问题