Recent

Author Topic: Try...except problem - cannot prevent the debug session from halting?  (Read 821 times)

Jeff_t

  • New Member
  • *
  • Posts: 17
Im trying to use an XML file.
I get a node, and want to get the value of some attributes.
Some attributes are optional.
If I ask for the value of an attribute that is not present in the file, it generates an exception and stops the running app in the IDE.
I expected that by wrapping the call inside a try...except  , that the issue would be more or less ignored, and the app would run.

However, even inside a try...except, the debugging app still stops and throws up a message.

Is there some way to prevent that ?

(In theory, the TDomNode should have a .HasAttribute method, but it doesnt seem to work for me.. )

Jeff_t

  • New Member
  • *
  • Posts: 17
Re: Try...except problem - cannot prevent the debug session from halting?
« Reply #1 on: September 23, 2025, 01:52:28 pm »
Later:
I have realised that the exception is because I put 'getting the attribute node'  and 'getting the nodevalue' as one line.
If the attribute doesn't exist, it returns a nil, which is reasonable.
and asking for a nodevalue from a nil is obviously bad.
So doing it in two steps avoids the exception.

However, the bigger problem still stands: if an exception does occur, wrapping it in try...except doesnt seem to allow me to ignore it.. it just stops with a message, so is there a way to stop that?

In a similar vein, if an exception occurs in an unexpected place, can I get the debugger to pause and say 'this is the place where a problem occurred'?

Zoran

  • Hero Member
  • *****
  • Posts: 1993
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Try...except problem - cannot prevent the debug session from halting?
« Reply #2 on: September 24, 2025, 10:52:26 am »
However, the bigger problem still stands: if an exception does occur, wrapping it in try...except doesnt seem to allow me to ignore it.. it just stops with a message, so is there a way to stop that?

The debugger stops on an exception. This does not happen outside of a debug session, does it? Try to run the program outside of the ide -- does it still happen?

This is the default debugger behaviour, to always stop on an exception, as it might be useful during debugging. If you don't need it and it annoys you, it can be turned off -- see: https://wiki.lazarus.freepascal.org/IDE_Window:_Project_Options_-_Debugger_Language_Exceptions -- uncheck "Notify on exceptions".
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12618
  • Debugger - SynEdit - and more
    • wiki
Re: Try...except problem - cannot prevent the debug session from halting?
« Reply #3 on: October 12, 2025, 12:52:32 pm »
-- see: https://wiki.lazarus.freepascal.org/IDE_Window:_Project_Options_-_Debugger_Language_Exceptions -- uncheck "Notify on exceptions".

That was broken, except for the GDB backend. In 4.99 that now works for all backends.

You can always check the "ignore this exception type" checkbox, when the notification comes. Then it wont show again (for that class / each class needs to be added once).

This is for each project. But you can save project settings as default for new projects (checkbox in lower left corner)

 

TinyPortal © 2005-2018