Page 1 of 1

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

Posted: Sun Mar 12, 2023 2:13 am
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.

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

Posted: Sun Mar 12, 2023 5:53 am
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.

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

Posted: Sun Mar 12, 2023 11:40 am
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.

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

Posted: Sun Mar 12, 2023 12:54 pm
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.

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

Posted: Sun Mar 12, 2023 1:03 pm
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.
??

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

Posted: Sun Mar 12, 2023 1:09 pm
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)

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

Posted: Sun Mar 12, 2023 1:43 pm
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 :)

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

Posted: Mon Mar 13, 2023 1:03 am
by BarryG
Thanks!