A Try...Catch... problem

What is going wrong with this piece of code (I don’t get the message in debug mode…)

Var MyDate As DateTime
Try
  MyDate = DateTime.FromString("31/02/2021",Locale.Current)
catch e as RunTimeException
  MessageBox("Date not valid")
End Try

Is Try...Catch only working after building the application? Not working in debug mode?

What behavior do you get?

I get a runtime error with MyDate = Nil. The application stops working

It does not stop working, it breaks in the Exception for you to debug it. Yo can disable the breaks in the menu Proyect -> Break on Exceptions

1 Like

You can click again the run (play) button and your code, which was paused, will resume.

Ivan, You are right… The project item Break on Exceptions was switched on in the IDE menu… Thank you for your help!

see also the use of

#Pragma BreakOnExceptions False

so the error handling would not stop at debug mode.
output also the exception object message at least for your own.

Yes Markus, I redefines #Pragma BreakOnExceptions TRUE/FALSE in several modules (e.g. database methods) but sometimes I rely too much on the IDE project menu item Break on Exceptions. And this is wrong: it’s better to define #Pragma BreakOnExceptions where you need it.

MS VB 6 had a better more sensible option in the ide.
if me made a error handling in xojo i usually for 99.9% not want that the app stops there in debug mode.
only unhandled errors are from interest.