Is this a compiler bug, or the doc needing more info?

Everything else that doesn't fall into one of the other PB categories.
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Is this a compiler bug, or the doc needing more info?

Post by BarryG »

Not sure if this is a compiler bug or lack of documentation, so I didn't put it in the Bug section.

The manual for OnErrorGoto() has this example code (and I added DisableDebugger at the top):

Code: Select all

DisableDebugger

MessageRequester("OnError test", "Test start")

OnErrorGoto(?ErrorHandler)
PokeS(10, "Hello World") ; Cause a #PB_OnError_InvalidMemory error

MessageRequester("OnError test", "This should never be displayed")
End

ErrorHandler:
MessageRequester("OnError test", "The following error happened: " + ErrorMessage())
End
If you run this from the IDE, you only get the first "Test start" message, and then the IDE raises a debug error. I would expect that it jumps to the ErrorHandler code and show "The following error happened", but it doesn't. So it seems OnErrorGoto() only works from a compiled executable, and not from the IDE? Using DisableDebugger makes no difference and the IDE still raises the error.

So... maybe this is a documentation issue, and the doc needs to explain that this command only works from a compiled exe? And if so, do the same explanation for the other OnError commands if it applies to them as well.
User avatar
yuki
Enthusiast
Enthusiast
Posts: 101
Joined: Sat Mar 31, 2018 9:09 pm

Re: Is this a compiler bug, or the doc needing more info?

Post by yuki »

I'm able to reproduce the same behaviour on Windows 11 (PB6.01, x64, C and ASM BEs): a single "Test start" message before stalling with an invalid memory error reported by the debugger.

Interestingly, on macOS 13.2.1 (PB6.01, arm64, C BE) the error handler is executed, regardless of whether I'm running compiled output or with debugger.

Regarding DisableDebugger, it only disables certain checks/output but should still catch fatal errors like this.
User avatar
HeX0R
Addict
Addict
Posts: 1204
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Is this a compiler bug, or the doc needing more info?

Post by HeX0R »

The sense behind the OnError library is to be able to catch errors outside of your developping environment.
It doesn't make much sense to let it run in parallel to the debugger at home, because the debugger is much stronger.

When you look into the docs:
https://www.purebasic.com/documentation ... index.html

you can see:
This way the final version of a program which is shipped to the end user can still intercept program errors and provide some information about the error to the user so he can report it back to the developer.
And that is the typical use case, trying to find bugs that only seem to happen on end-users side.

I usually don't use it, until I get reports from end users about phenomenons I can't explain.
Then I simply paste that here on top of my application and activate the onError switch of the compiler and send it back to the user.
Fred
Administrator
Administrator
Posts: 18225
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Is this a compiler bug, or the doc needing more info?

Post by Fred »

@HeX0R: that's the correct way to use it. The debugger itself install its own error handler so it mess up with OnError. You need to disable it completely to have it working as expected.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2139
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Is this a compiler bug, or the doc needing more info?

Post by Andre »

So it's probably a good idea to extend the existing 'Note' in the OnError library docs
Note: If both this library and the PureBasic debugger are used, not all errors will be caught by the OnError library as some checks are made and reported by the debugger even before the actual code with the error is executed.
with another one or two sentences like this
So it's recommended to use DisableDebugger when creating the final executable. During development and testing the PB debugger should be used.
??
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Fred
Administrator
Administrator
Posts: 18225
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Is this a compiler bug, or the doc needing more info?

Post by Fred »

When creating an executable the debugger is always disabled. The current note is OK IMHO, but we might add:
To test OnError in the IDE, be sure to turn off the debugger (DisableDebugger is not enough)
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2139
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Is this a compiler bug, or the doc needing more info?

Post by Andre »

Fred wrote: Sun Mar 12, 2023 1:09 pm When creating an executable the debugger is always disabled. The current note is OK IMHO, but we might add:
To test OnError in the IDE, be sure to turn off the debugger (DisableDebugger is not enough)
Added :)
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: Is this a compiler bug, or the doc needing more info?

Post by BarryG »

Thanks!
Post Reply