Announcement

Collapse
No announcement yet.

GetLastError vs Err

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GetLastError vs Err

    I am trying to be careful to not mix-match terminology, but.
    for this question think of DDT = PB Functions, and SDK = API Functions


    If an error occurs does that error code only exist until another function sets or resets that value? or is it only good for the next line of code?

    I understand that I can not call a DDT style function and expect a API style check for error can not work (or report incorrectly) and the other way around. but for lack of a better example if there were 2 functions 1 as DDT one as SDK, when would the ERROR get reset?

    DDT and SDK Fake Function DivideByZero
    Code:
         '5 divide by 0     'Should raise error
         'results times 12     'Error Still Exist?
         'pass to another function to multiply by 10      'Error still exist? or reset to 0 because I left this function? or only reset if the other function purposely reset the error value?
    For either side, I know if you code correctly you can find the cause of the error, but wonder when it gets reset? (Only when I do it? or a function does it just like if I did it?, or 1 line after?)

    Sounds like a chicken-egg thing but hopefully someone gets what I am trying to figure out.

    Also the line "ON ERROR" do yadda yadda, if I read right somewhere in the Win32 help files would be like checking if value = error value then do yadda yadda, so forgive my VB Refugee mind, but does PB catch an error that was caused by a call to a API function? (It appears it does in most cases, but wondered if that was for simplicity sake? or deeper?) Since I think if I wanted to say "ON VALUE = %TRUE GOTO" kind of thought.

    Rather rough description, but if need I will see if I can figure out a sample to demo where I am confused.
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    ERR returns the last PB error that occurred, regardless when it happened. If you want it cleared, call ERRCLEAR instead of ERR

    GetLastError returns the last Windows API error. Should only be called IF there is an error. (API function returned an error)
    Regards,
    Peter

    Comment


    • #3
      > '5 divide by 0 'Should raise error

      No, it won't because the PowerBASIC compiler does not provide overflow checking.

      I have sent in my New Feature Suggestion to add same via a compile-time option...
      Code:
      #DEBUG OVERFLOW ON|OFF  ' default OFF for backward compatibility
      .. and you, too can send in a "vote" for that.

      In the actual case, the most likely results are data corruption or a divide by zero protection fault.
      Michael Mattias
      Tal Systems Inc. (retired)
      Racine WI USA
      [email protected]
      http://www.talsystems.com

      Comment

      Working...
      X