Debugger only break on exceptions outside try...catch?

Hi,
is it possible to tell the debugger to only break on exceptions which appear outside of a try…catch block…

Any ideas? This would make debugging much more efficient for me.

[quote=451146:@Daniel Fritzsche]Hi,
is it possible to tell the debugger to only break on exceptions which appear outside of a try…catch block…[/quote]

Of course! With a BreakOnExceptions Pragma directive.

See http://documentation.xojo.com/api/language/pragma_directives.html

Thanks for the tip in this direction. I tried this and so far it works, but now another problem appears. This way the debugger also won’t break when an exception is not caught, right?.

Any ideas how to reach that?

Doesnt this do it?

#Pragma BreakOnExceptions False try dim x as bevelbutton x.caption = "hello"//ouch catch end try #Pragma BreakOnExceptions default

For that “outside of a try-catch-block” you’ve got your answer.

Am I assuming correct: That’s a different situation?
Are you maybe thinking of some other Exception that occurs within the try-catch Block?
Let’s take this as an example:

try #Pragma BreakOnExceptions False Dim arrayDate() As Date for i As Integer = 1 to 10 Dim d As New Date if (i = 5) then d = nil if (d.Year = 2019) then arrayDate.Append(d) next catch err As OutOfBoundsException MsgBox "catched an OOB-Exception" finally #Pragma BreakOnExceptions True end try

So if you’re asking: “How to NOT break on the catched Exception(s), but DO break on the line of Code of any other Exception?” Then… I don’t have an answer for that :frowning:

I am not sure either if this is possible, but how about displaying a MsgBox while in DebugMode if your handled exceptions did not handle the exception?

#Pragma BreakOnExceptions False try dim x as bevelbutton x.caption = "hello"//ouch Catch e As RunTimeException If e IsA EndException Or e IsA ThreadEndException Then // Do this... Else If DebugMode Then MsgBox(e.Message) End If #Pragma BreakOnExceptions default

Source: http://documentation.xojo.com/api/code_execution/try.html

… or simply

#Pragma BreakOnExceptions False try dim x as bevelbutton x.caption = "hello"//ouch Catch e As RunTimeException If e IsA EndException Or e IsA ThreadEndException Then // Do this... Else #Pragma BreakOnExceptions default Raise e End If #Pragma BreakOnExceptions default

Hi,
thanks everyone. I have changed the code a bit because it looks a little bit prettier from my point of view and I can now focus on the exceptions I did not caught.

#Pragma BreakOnExceptions False try dim x as bevelbutton x.caption = "hello"//ouch Catch me1 As MyException1 #Pragma BreakOnExceptions default 'handle the planned exception Catch me2 As MyException2 #Pragma BreakOnExceptions default 'handle the planned exception Catch re As RunTimeException 'this is for unhandled exceptions... #Pragma BreakOnExceptions default Raise re End Try

My apologies if I’m misunderstanding the challenge (if it’s not already solved), but is the “Break on Exceptions” menu item checked under the Xojo IDE “Project” menu?

Before I discovered the #Pragma BreakOnExceptions feature, I was occasionally turning this menu option off for known exception conditions, but forgetting to turn it back on and wondering why the debugger wasn’t catching some things.

Good luck.

The thing is that if you have let’s say 50 lines of code between try and catch, you still don’t get the Debugger to break on the exact line of code where an unhandled exception occurs (but not have the Debugger break if a handled exception occurs).
It’ll break on the bottom in the Catch re As RunTimeException. So to figure out where the exception really occured, you’d need to change again to #Pragma BreakOnExceptions True for the method, and reproduce it again.
Not as convenient as it could be.

It might be worth adding a Feature Request for that in Feedback… something like a #pragma BreakOnlyOnUnhandledExceptions would be quite nice to have. Not sure if that’s possible though…

Sounds like the enhancement I logged last year:
<https://xojo.com/issue/51804>