43

I am Debugging some BOOST unit tests in QtCreator and it sadly happened that they crash with an exception. How can I make QtCreator automagically break if any exception is raised? In Visual Studio there is a tick box for this one, is it also available in QtCreator?

In my case, BOOST catches the exception, so the program doesn't technically crash. However, the reported message is not really helpful.

I tried the same in KDevelop previuosly, hence I am asking separate questions about both of these IDEs.

Grzenio
  • 35,875
  • 47
  • 158
  • 240

2 Answers2

67
  • Open Debug mode (Ctrl+F4 or just 4th mode on right bar).

    enter image description here

  • Open context menu in breakpoints list at right bottom:

    enter image description here

  • Select "Add Breakpoint" and set the breakpoint type to "Break when C++ exception is thrown":

    enter image description here

Community
  • 1
  • 1
Sergey Shambir
  • 1,562
  • 12
  • 12
  • 3
    Is there a way to choose to break on a certain type/class of exception? – Silicomancer May 08 '19 at 12:26
  • 5
    I have DEFINITELY checked the "C++ Exception" box in the "Break on:" category, but for some reason Qt Creator refuses to break on the exception. I know for a fact that an exception is being thrown because I have a "catch ( const std::exception& exc )" clause in which I print the return value of the exc object's what() method, and it says "std::bad_alloc". :( – antred Jan 16 '20 at 16:36
  • I am seeing std::map trow an out_of_range exception, with the solution in the above answer enabled, yet QtCreator (4.11.1) still isn't breaking, just terminating the program =[ – Troyseph Apr 13 '20 at 09:13
  • I have a similar problem with a Qtest Project. It seems that QTest does not care about this setting – A. Ocannaille Jan 29 '21 at 14:16
0

In QTcreator 8.0.2, this worked for me without adding any additional breakpoints:

Edit --> preferences --> Debugger --> GDB Extended --> Enable "Stop when aport() is called"

enter image description here

alireza
  • 101
  • 4