I am trying to use lldb for c++ debugging and I want to halt if an exception is thrown, like gdb's catch throw, and I cannot find an equivalent in the lldb documentation.
            Asked
            
        
        
            Active
            
        
            Viewed 2.8k times
        
    3 Answers
80
            
            
        Use breakpoint set -E c++ to break on all exceptions and breakpoint set -F std::range_error  to break on a specific exception.
 
    
    
        Lucian Adrian Grijincu
        
- 2,491
- 2
- 18
- 18
 
    
    
        Jonas K
        
- 4,215
- 2
- 24
- 25
62
            In Xcode, you can set an Exception breakpoint (View > Navigators > Show Breakpoint Navigator, hit the + button in the bottom of the breakpoint list window to add a new breakpoint).
If you're using command line lldb, put a breakpoint on __cxa_throw for C++ exception throws, objc_exception_throw for Objective-C exception throws.
For all c++ exceptions: break set -E C++.
 
    
    
        Ven
        
- 19,015
- 2
- 41
- 61
 
    
    
        Jason Molenda
        
- 14,835
- 1
- 59
- 61
- 
                    16for all c++ exceptions: break set -E c++ – plaisthos Oct 08 '12 at 11:33
- 
                    1ah, I missed the -E option to breakpoint set! Thanks for noting it. – Jason Molenda Oct 08 '12 at 19:03
- 
                    3The '-F' and '-E' variants weren't working for me, but 'breakpoint -n __cxa_throw' did work (for all exceptions), as well as 'breakpoint -n' (for specific exceptions). – Anthony Hall May 26 '15 at 18:56
- 
                    1"-E objc" also works if you want Objective-C exceptions. – Maurice Gilden Jul 02 '18 at 08:24
- 
                    `break set -E c++` didn't work for me (perhaps because I'm using real GNU g++ instead of Apple's clang++?), but `break set -n __cxa_throw` did. @AnthonyHall's comment is lacking `set`. – Mark Gates Feb 12 '19 at 22:16
0
            
            
        I think breakpoint set -w <boolean> is the correct answer, you can use help breakpoint set to see the document.
 
    
    
        Casa Taloyum
        
- 1
- 1
