有時程序中有未捕獲的異常會致使程序異常的行爲甚至致使程序的直接退出。 這對服務器程序來講是不可接受的。服務器
可使用gdb的catch命令來幫助咱們調試異常。線程
使用gdb捕獲異常的扔出點(至關於在扔出異常的地方添加斷點):debug
catch throw
使用gdb捕獲線程退出(至關於在線程退出的時候添加斷點):調試
catch pthread_exit
這樣,若是相應的事件發生,gdb就會中斷程序的執行, 就可使用gdb的bt命令來檢查出現錯誤的調用棧了。code
更多信息:blog
(gdb) help catch Set catchpoints to catch events. Raised signals may be caught: catch signal - all signals catch signal <signame> - a particular signal Raised exceptions may be caught: catch throw - all exceptions, when thrown catch throw <exceptname> - a particular exception, when thrown catch catch - all exceptions, when caught catch catch <exceptname> - a particular exception, when caught Thread or process events may be caught: catch thread_start - any threads, just after creation catch thread_exit - any threads, just before expiration catch thread_join - any threads, just after joins Process events may be caught: catch start - any processes, just after creation catch exit - any processes, just before expiration catch fork - calls to fork() catch vfork - calls to vfork() catch exec - calls to exec() Dynamically-linked library events may be caught: catch load - loads of any library catch load <libname> - loads of a particular library catch unload - unloads of any library catch unload <libname> - unloads of a particular library The act of your program's execution stopping may also be caught: catch stop C++ exceptions may be caught: catch throw - all exceptions, when thrown catch catch - all exceptions, when caught Do "help set follow-fork-mode" for info on debugging your program after a fork or vfork is caught. Do "help breakpoints" for info on other commands dealing with breakpoints.
轉自http://blog.chenming.info/blog/2008/04/16/handle-exception-in-gdb/事件