Recent

Author Topic: [SOLVED] Detect if a memory is valid  (Read 3014 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: [SOLVED] Detect if a memory is valid
« Reply #30 on: November 22, 2022, 04:38:29 pm »
The best way to evaluate that is a repeatable crash.... 8-) That is not a joke. You can take precautionary measures  to avoid it, but not much else.
« Last Edit: November 22, 2022, 04:40:04 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Okoba

  • Hero Member
  • *****
  • Posts: 533
Re: [SOLVED] Detect if a memory is valid
« Reply #31 on: November 22, 2022, 04:40:25 pm »
:D I needed the laugh, thank you.

TO summarize I want to know two things now:
1- A question I have is that in debug mode, Lazarus uses exception handling that leads to the message box. Where was it set?
2- Is it safe swapping exception handling functions in the the previous code I posted, using try finally?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: [SOLVED] Detect if a memory is valid
« Reply #32 on: November 22, 2022, 09:30:30 pm »
1- A question I have is that in debug mode, Lazarus uses exception handling that leads to the message box. Where was it set?

It's triggered by the debugger, not the application.

2- Is it safe swapping exception handling functions in the the previous code I posted, using try finally?

No, because that is not thread safe. Just do as Thaddy said: just access the memory and trigger a potential exception and catch that using tryexcept.

Okoba

  • Hero Member
  • *****
  • Posts: 533
Re: [SOLVED] Detect if a memory is valid
« Reply #33 on: November 23, 2022, 09:21:40 am »
Quote
It's triggered by the debugger, not the application.
Interesting, so the GDB or FPDebugger act as the exception manager before it gets to the program.

Quote
No, because that is not thread safe. Just do as Thaddy said: just access the memory and trigger a potential exception and catch that using try … except.
My question controlling that exception without SysUtils. Now that I found it thanks to you, and my program is not threaded, I can have my way.

Thank you all.

Okoba

  • Hero Member
  • *****
  • Posts: 533
Re: [SOLVED] Detect if a memory is valid
« Reply #34 on: November 23, 2022, 10:49:49 am »
@PascalDragon Is there a way to tell debugger, to not control the exception? I still like to have the debug info, without the debugger middling in exception handling.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: [SOLVED] Detect if a memory is valid
« Reply #35 on: November 23, 2022, 11:10:19 pm »
Quote
It's triggered by the debugger, not the application.
Interesting, so the GDB or FPDebugger act as the exception manager before it gets to the program.

It's the purpose of a debugger to be able to catch exceptions of an application so that the developer can investigate them.

Quote
No, because that is not thread safe. Just do as Thaddy said: just access the memory and trigger a potential exception and catch that using try … except.
My question controlling that exception without SysUtils. Now that I found it thanks to you, and my program is not threaded, I can have my way.

That doesn't change that changing these functions is not thread safe.

@PascalDragon Is there a way to tell debugger, to not control the exception? I still like to have the debug info, without the debugger middling in exception handling.

Project -> Project Settings -> Project Settings -> Language Exceptions. Add the class name to the list, though I don't know whether the debugger does special checks that the class inherits from Exception.

Okoba

  • Hero Member
  • *****
  • Posts: 533
Re: [SOLVED] Detect if a memory is valid
« Reply #36 on: November 23, 2022, 11:11:46 pm »
Thank you!

 

TinyPortal © 2005-2018