enable_Debug_GetLastError

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Captn. Jinguji
User
User
Posts: 94
Joined: Sun Oct 24, 2004 9:25 am

enable_Debug_GetLastError

Post by Captn. Jinguji »

enable_Debug_GetLastError
Have debug execute GetLastError_() implicitly and, if its return is not 0,
output an extra line showing the error code and a textual representation of the error constant name.

disable_Debug_GetLastError
disable implicit GetLastError_() execution/reporting.

e.g.

Code: Select all

enable_Debug_GetLastError 
debug readfile( 1, filename )  
disable_Debug_GetLastError
yields:

Code: Select all

0
<32:ERROR_SHARING_VIOLATION>
Is this an artifact or should it be disposed of ?
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: enable_Debug_GetLastError

Post by nco2k »

a pb function usually uses multiple winapi functions, that all could produce different errors. i dont see how this would help you, unless you know which winapi function produced that error.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Captn. Jinguji
User
User
Posts: 94
Joined: Sun Oct 24, 2004 9:25 am

Re: enable_Debug_GetLastError

Post by Captn. Jinguji »

Oh, incidentally , we had a current case in the german forum where a file wouldn't open in some cases: it had to be win7 with a service pack installed while win7 without svc pack or win 10 worked as expected; also, the error did not occur with win7.SP1 when the accesses were more than 60 seconds apart. Don't we all just love errors like that ?

getlasterror_() was the key to the solution, since no other indication why the file wouldn't open was given.

Also: There have been other ocassions where getlasterror_() helped significantly.

Also: If internally, one of a multi-winapi call of a PB function should fail, I'd expect the function to fail at that call, with LastError set correspondingly. Why should the PB function execute subsequent winapi calls after the failed winapi call and thus possibly reset LastError ?

That's how!
Is this an artifact or should it be disposed of ?
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: enable_Debug_GetLastError

Post by nco2k »

Also: There have been other ocassions where getlasterror_() helped significantly.
im not doubting the usefulness of GetLastError_(), but only when you have control over it between each individual winapi call.
Also: If internally, one of a multi-winapi call of a PB function should fail, I'd expect the function to fail at that call, with LastError set correspondingly. Why should the PB function execute subsequent winapi calls after the failed winapi call and thus possibly reset LastError ?
who said anything about executing a subsequent function after a failure? some of the error codes are very cryptic, and unless you know the name of the function that caused it, you wont get far. by looking at the name of a pb function, you can pretty easily figure out the main winapi function thats being used internally. but that function might not be the one causing that error. it may be a function thats not that obvious, and is being called before or after the obvious one. in order for that error code to be useful, pb would also need to tell you which winapi function caused it. but then again pb could tell you all the winapi functions its using, or even better, make the whole language open source. :)

also some of the uninit winapi functions inside the pb function could overwrite the error code. so if you want this to work reliably, fred would have to add GetLastError_() between every single winapi call and preserve the results in case you want to debug them.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Post Reply