Announcement

Collapse
No announcement yet.

Error Handling - Line Numbers

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

  • Error Handling - Line Numbers

    PB has the ability to show me what line number that an error occurred that makes your code uncompilable.
    Is there a way to get this line number if the code compiles, but causes an error at run time???

    I am working on improving my errorhandling routines, and this would be of great benefit if it is possible?
    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
    ERL$ (CC5+, Win 9+) and ERL (any) come to mind.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Nice One MCM, but that is what I am currently doing. And 1 minor points that make this hardcoded instead of real ("Where did I go wrong?")

      ERL = With ERL, line numbers are of the traditional-basic line numbering variety, not the physical source code line.

      Aka line numbers I physically place at the beginning of the line of code

      On posting this, I dug a lil deeper and ERL$ looks interesting, but initial tests show that the last label, function, or line number will be returned, but maybe I can come up with an idea to add line numbers or labels at run time (or compile time) rather than hard code them myself???)
      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? "

      Comment


      • #4
        >but maybe I can come up with an idea to add line numbers or labels at run time (or >compile time) rather than hard code them myself???)

        As long as you don't use GOTO or GOSUB in any of their myriad forms, a pre-compiler to add line numbers should be pretty easy to create.

        However, the line number at which an error is detected is not necessarily, " Where did I go wrong?"

        I just did this myself this AM. Program exited (cleanly, which was weird) because I overflowed the stack with an inadvertent recursion. (Thank you "TRACE" for indenting the entries about 200 columns to the right before the program died).

        Where I had gone wrong was not at any detectable line number, it was in thinking I could do what I had coded without something bad happening.

        MCM
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Originally posted by Cliff Nichols View Post
          On posting this, I dug a lil deeper and ERL$ looks interesting, but initial tests show that the last label, function, or line number will be returned, but maybe I can come up with an idea to add line numbers or labels at run time (or compile time) rather than hard code them myself???)
          Check this. I have wrote it much time ago (for exactly this purpose), so it may need some tweaks for new keywords / constructs, but it should help:

          Source Code - Add line numbers to a PB source

          Bye!
          -- The universe tends toward maximum irony. Don't push it.

          File Extension Seeker - Metasearch engine for file extensions / file types
          Online TrID file identifier | TrIDLib - Identify thousands of file formats

          Comment


          • #6
            Thanks for the ideas guys.
            I kinda figured I may need to do a precompile to add line numbers or labels, (Although I am trying to think up a way to have a macro insert the label, rather than a precompile)

            MCM, I know what you mean, ever since I started adding my error handler to my programs, I have caught many times I did something wrong, and just lucked out that it has worked all these years.

            Although I can not always get "Where did I go wrong", I know with this I can home in on "Where did I go wrong" a lot faster than I can just by reading function by function (especially in large projects I wrote long ago)

            This will be a HUGE step in my error handling and debugging
            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? "

            Comment


            • #7
              This is what I have so far, but on RESUME NEXT, I continue after the label, and not before the label.

              ErrorHandling.inc
              Code:
              '*** ErrorHandling.inc
              '***      Written by: Cliff Nichols - 08-28-2008
              '***      Modified by: Cliff Nichols - 11-01-2008
              '***      Compiler: 8.04/9.0
              '***      Should work on: 7/8/9
              '***      Tested on: XP-Pro SP3, Vista-Ultimate
              '***      Should work on: 95/98/ME/NT/2K/XP/Vista
              '***      Purpose - Beefed up Error Handling Routines to attempt to "Bullet-Proof" apps
              '*** Usage:
              '***      StartTrace - Create a Trace log file
              '***      TraceVariables - Common Variables for each function
              '***
              '***      TraceUnHandledFunction - Steps for anything that you did not think of when writing and testing your code
              '--------------------------------------------------------------------------------
              '*** Now for the FUN Stuff
              '***      PB has 'On Error' for handling errors on the DDT side
              '***           PB can raise an error just by ERR = some number
              '***      Windows has 'GetLastError' to check any errors via SDK
              '***           Windows has to check for errors and handle them (errors are not raised)
              '***      Windows has "Exceptions" (You've seen them...the default usually shows the typical "*.exe has encountered a problem and needs to close" message)
              '***           Windows "Exceptions" can be raised, but default handler is typically fatal, but you can override that fatality
              '*** I REALLLLLLY want to know how to do the below without visibly inserting numbers but.....
              '***      PB Line numbers (if inserted) can assist in locating where an error occured (larger projects its smarter to contain line numbers to their functions)
              '***      PB FUNCNAME$ in conjunction with the line numbers can nail down what line the error occured on
              '***           Conjunction, junction, whats your function??? :-)
              '*** What makes it all work????
              '*** MACRO's baby, yeah baby yeah...(Finally got this one when larger code all had the same multiple commands and got tedious to type or copy/paste)
              '*** Globals.....Real Men don't need no stinkin Globals :-) (Finally got this one working deep with Windows API...See "Parameter as Reply" discussion)
              '***
              '***
              '*** 11-01-08
              '***      Added line numbers to everything so line numbers for functions/subs/macros should start at 100 and up for future use of added macros
              '--------------------------------------------------------------------------------
              
              '*** If not already declared in your code, then declare this INC
              #IF NOT %DEF(%ERRORHANDLING)
                   %ERRORHANDLING = 1
              '*** Globals
              '***      NONE
              '***           - Use SetGetDebugTraceRunning to keep value in replacement for a global DebugTraceRunning
              '***           - Use SetGetLastFunction to keep value in replacement for a global LastFunction
              '*** Constants
                   %UNKNOWN_VALUE = -1
                   %RESUME = 0
                   %RESUMENEXT = 1
                   %NORESUME = -1
              '*** Constants not found in Win32Api.Inc
                   %EXCEPTION_ILLEGAL_INSTRUCTION  = &HC000001D
                   %EXCEPTION_STACK_OVERFLOW       = &HC00000FD
              '*************************************************************************************************************
              '*** Macro's - When Compiled, replace the name of the macro with all the functions and processes in the macro
              '***           As if you had done it yourself in each and every SUB/FUNCTION it was called
              '***           Do not add line numbers to Macro's unless you want to renumber functions that use the macros
              '*************************************************************************************************************
              '*** TraceUnHandledFunction
              '***      Macro to replace code at the end of each function being being debugged
              '***           Code will jump to end ON ERROR or if told to jump to end
              '***           Code relies on TraceVariables to compile
              '***                11-01-08 Added Macros to work with Functions/Subs/Methods
              '*************************************************************************************************************
              '*** Function
                   MACRO TraceUnHandledFunction
              15        EXIT FUNCTION                                               'Exit to not Execute Function code again
              16        TraceUnHandled
                   END MACRO
              '*** Sub
                   MACRO TraceUnHandledSub
              15        EXIT SUB                                               'Exit to not Execute Function code again
              16        TraceUnHandled
                   END MACRO
              '*** Method
                   MACRO TraceUnHandledMethod
              15        EXIT METHOD                                               'Exit to not Execute Function code again
              16        TraceUnHandled
                   END MACRO
              '*** Trace all Unhandled
                   MACRO TraceUnHandled
              20   ErrHandler:
              21        ErrFunc = GetLastError                                      'Get API Last Error
                        #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL, ERL$
                        #ELSEIF (%PB_REVISION) < &H900
              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL
                        #ENDIF
              23        SetUnhandledExceptionFilter %NULL
              24        SetGetOverRideError(%UNKNOWN_VALUE, OverRideError, %UNKNOWN_VALUE)
              MSGBOX STR$(OverRideError)
              25        SELECT CASE OverRideError
              26             CASE %RESUME, 0
              27                  SetLastError(0)
              28                  ERRCLEAR
              29                  RESUME
              30             CASE %RESUMENEXT, 1
              31                  SetLastError(0)
              32                  ERRCLEAR
              33                  RESUME NEXT
              '33                  goto 7
              34             CASE %NORESUME, -1
              35        END SELECT
                   END MACRO
              '*************************************************************************************************************
              '*** TraceVariables
              '***      Macro to replace code at the begginning of each function being being debugged
              '***           Code sets up variables to jump to end ON ERROR or if told to jump to end
              '***           Code relies on TraceUnHandledFunction to compile
              '*************************************************************************************************************
                   MACRO TraceVariables
              1         ON ERROR GOTO ErrHandler                                    'Avoid using error numbers higher than 240, as they are reserved for use in critical error situations which can never be trapped with ON ERROR.
              2         LOCAL DebugTraceRunning AS LONG                             'Variable for if debugging
              3         LOCAL LastErrorValue AS LONG                                'Variable for GetLastError
              4         LOCAL PbErrorValue AS LONG                                  'Variable for PB ERR
              5         LOCAL ErrorLineNumber AS LONG                               'Variable for line number where the error occured (or the last checked line)
              6         LOCAL ErrFunc AS LONG                                       'Variable for if there was an error in the function
              7         LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH                       'Variable for Win32Api Error Description
              8         LOCAL WhatToTrace AS STRING                                 'Variable for what to log for an error
              9         LOCAL OverRideError AS LONG                                 'Variable for if to continue even if there is an error
              10        SetLastError(0)                                             'Ensure the last Windows error is cleared
              11        ERRCLEAR                                                    'Ensure the last PB error is cleared
              '          SetUnhandledExceptionFilter %EXCEPTION_EXECUTE_HANDLER      '<--- Use this exception handler if wanting to use windows default (the typical "*.exe has encountered a problem and needs to close" message)
              12        SetUnhandledExceptionFilter CODEPTR (TraceExceptionHandler) '<--- Use this exception handler if wanting to make a better crash-proof program
                   END MACRO
              '*************************************************************************************************************
              '*** TraceOn
              '***      Macro to replace code that would be blindly TRACE ON
              '***           Code only turns the trace on if debugging
              '***           Leaving a function will turn TRACE OFF by default (although I like to purposely call it to clean up after myself)
              '*************************************************************************************************************
                   MACRO TraceOn
              50        ErrFunc = SetGetDebugTraceRunning(%UNKNOWN_VALUE, DebugTraceRunning, %UNKNOWN_VALUE)      '<---Find out if debugging or not
              51        SELECT CASE DebugTraceRunning
              52             CASE 0                                                 'Not running a trace
              53             CASE ELSE
              54                TRACE ON                                          'Turn on trace if debugging
              55          END SELECT
                   END MACRO
              '*************************************************************************************************************
              '*** TraceOff
              '***      Macro to replace code that would be default TRACE OFF
              '***           Code only turns the trace off if debugging
              '***           Leaving a function will turn TRACE OFF by default (although I like to purposely call it to clean up after myself)
              '*************************************************************************************************************
                   MACRO TraceOff                                                   '<--- Not needed if exiting function but I am a stickler
              60        ErrFunc = SetGetDebugTraceRunning(%UNKNOWN_VALUE, DebugTraceRunning, %UNKNOWN_VALUE)
              61        SELECT CASE DebugTraceRunning
              62             CASE 0                                                 'Not running a trace
              63             CASE ELSE
              64                  TRACE OFF                                         'Turn off trace if debugging
              65        END SELECT
                   END MACRO
              '*************************************************************************************************************
              '*** LastErrorCheck
              '***      Macro to replace code that would be multiple lines for Win32Api GetLastError
              '***           Code only traces if debugging
              '***           TraceLastError will decide if a Windows or a PB Error and log accordingly
              '*************************************************************************************************************
              70   MACRO LastErrorCheck
              71        ErrFunc = GetLastError                                      'Get API Last Error
                        #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
              72             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL, ERL$                 'Pass all known info to the function for logging
                        #ELSEIF (%PB_REVISION) < &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
              72             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL                 'Pass all known info to the function for logging
                        #ENDIF
                   END MACRO
              '*************************************************************************************************************
              '*** NOW FOR THE STANDARD INC SETUP
              '*************************************************************************************************************
              '*** Declares:
                   DECLARE FUNCTION SetGetDebugTraceRunning(ValueToSet AS LONG, ValueResults AS LONG, ResetValue AS LONG) AS LONG
                   DECLARE FUNCTION SetGetLastFunction(ValueToSet AS STRING, ValueResults AS STRING, ResetValue AS LONG) AS LONG
                   DECLARE FUNCTION SetGetOverRideError(ValueToSet AS LONG, ValueResults AS LONG, ResetValue AS LONG) AS LONG
                   DECLARE FUNCTION StartTrace ALIAS "StartTrace"() AS LONG
                   DECLARE FUNCTION EndTrace ALIAS "EndTrace"() AS LONG
                   DECLARE FUNCTION TraceProgramName(ParentAppName AS ASCIIZ * %MAX_PATH) AS LONG
                   DECLARE FUNCTION TraceLastError(FunctionName AS STRING, LastErrorValue AS LONG, PbErrorValue AS LONG, OPTIONAL ErrorLineNumber AS LONG, OPTIONAL ErrorLineString AS STRING) AS LONG
                   DECLARE FUNCTION TracePrint(WhatToTrace AS STRING) AS LONG
                   DECLARE FUNCTION TraceExceptionHandler(BYREF lpEP AS EXCEPTION_POINTERS) AS LONG
              '*** Dependant Inc Files:
              '***      None
              '*** Functions:
              '***      SetGetDebugTraceRunning Replaces the need for global variables so that local variables in other functions are easier to read
                   FUNCTION SetGetDebugTraceRunning(ValueToSet AS LONG, ValueResults AS LONG, ResetValue AS LONG) AS LONG
              101       TraceVariables                                              'Macro for Declaring variables for error checking
              102       STATIC FunctionValue AS LONG                                'Static to hold current value
              103       SELECT CASE ResetValue                                      'Decide whether to Set or to Get the current value
              104            CASE %False, %UNKNOWN_VALUE                            'If set to False, or -1 Then Get Current Value
              105                 ValueResults = FunctionValue                      'Return Results as a parameter
              106            CASE = %TRUE                                           'If set to True then Reset the Current Value
              107                 FunctionValue = ValueToSet                        'Reset the value
              108                 ValueResults = FunctionValue                      'Return Results as a parameter
              109       END SELECT
              110      FUNCTION = %False                                           'Return if Function Failed
              111      TraceUnHandledFunction                                              'Exit Function or handle unhandled errors
                   END FUNCTION
              '*** SetGetLastFunction Replaces the need for global variables so that local variables in other functions are easier to read
                   FUNCTION SetGetLastFunction(ValueToSet AS STRING, ValueResults AS STRING, ResetValue AS LONG) AS LONG
              101       TraceVariables                                              'Macro for Declaring variables for error checking
              102       STATIC FunctionValue AS STRING                              'Static to hold current value
              103       SELECT CASE ResetValue                                      'Decide whether to Set or to Get the current value
              104            CASE %False, %UNKNOWN_VALUE                            'If set to False, or -1 Then Get Current Value
              105                 ValueResults = FunctionValue                      'Return Results as a parameter
              106            CASE = %TRUE                                           'If set to True then Reset the Current Value
              107                 FunctionValue = ValueToSet                        'Reset the value
              108                 ValueResults = FunctionValue                      'Return Results as a parameter
              109       END SELECT
              110       FUNCTION = %False                                           'Return if Function Failed
              111       TraceUnHandledFunction                                              'Exit Function or handle unhandled errors
                   END FUNCTION
              '*** SetGetOverRideError Replaces the need for global variables so that local variables in other functions are easier to read
                   FUNCTION SetGetOverRideError(ValueToSet AS LONG, ValueResults AS LONG, ResetValue AS LONG) AS LONG
              101       TraceVariables                                              'Macro for Declaring variables for error checking
              102       STATIC FunctionValue AS LONG                              'Static to hold current value
              103       SELECT CASE ResetValue                                      'Decide whether to Set or to Get the current value
              104            CASE %False, %UNKNOWN_VALUE                            'If set to False, or -1 Then Get Current Value
              105                 ValueResults = FunctionValue                      'Return Results as a parameter
              106            CASE = %TRUE                                           'If set to True then Reset the Current Value
              107                 FunctionValue = ValueToSet                        'Reset the value
              108                 ValueResults = FunctionValue                      'Return Results as a parameter
              109       END SELECT
              110       FUNCTION = %False                                           'Return if Function Failed
              111       TraceUnHandledFunction                                              'Exit Function or handle unhandled errors
                   END FUNCTION
              '*** Start Tracing
                   FUNCTION StartTrace ALIAS "StartTrace"() EXPORT AS LONG
              101       TraceVariables                                              'Macro for Declaring variables for error checking
              102       LOCAL TraceLogName AS ASCIIZ * %MAX_PATH
              103       ErrFunc = TraceProgramName(TraceLogName)                    'Get a trace log name
              104       SELECT CASE ErrFunc                                         'If no error creating the log
              105            CASE %FALSE
              106                 DebugTraceRunning = %TRUE                         'Set variable for if tracing
              107                 TRACE NEW TraceLogName                            'Create the log
              108            CASE ELSE                                              'Some Error Occurred
              109       END SELECT
              110       ErrFunc = SetGetDebugTraceRunning(%TRUE, DebugTraceRunning, %TRUE)    'Set the flag that we are tracing
              111       TraceUnHandledFunction                                              'Macro for Local Variables and Unhandled Errors
                   END FUNCTION
              '*** End Tracing
                   FUNCTION EndTrace ALIAS "EndTrace"() EXPORT AS LONG
              101        TraceVariables                                             'Macro for common variables
              102        LOCAL TraceLogName AS ASCIIZ * %MAX_PATH
              103        ErrFunc = TraceProgramName(TraceLogName)                   'Get a trace log name
              104        SELECT CASE ErrFunc                                        'If the trace log name exists (no error) then
              105             CASE %FALSE
              106                  DebugTraceRunning = %FALSE
              107                  TRACE CLOSE                                      'Close Trace File
              108             CASE ELSE                                             'Some Error Occurred
              109        END SELECT
              110        ErrFunc = SetGetDebugTraceRunning(%FALSE, DebugTraceRunning, %TRUE)      'Set the flag for we are no longer tracing
              111        TraceUnHandledFunction                                            'Macro for Local Variables and Unhandled Errors
                   END FUNCTION
              '*** Set up a log file name
                   FUNCTION TraceProgramName(ParentAppName AS ASCIIZ * %MAX_PATH) AS LONG
              101        LOCAL ErrFunc AS LONG
              102        LOCAL ModuleHandle AS DWORD
              '102        ErrFunc = GetModuleFileName(GetModuleHandle(BYVAL %NULL), ParentAppName, %MAX_PATH)       'Returns current path to owning parent
              '103        ParentAppName = MID$(ParentAppName, 1, INSTR(ParentAppName, ".exe") - 1)  'Strip all but the parent '.exe' part
              103        ModuleHandle = GetModuleHandle($NUL)
              104        GetModuleFileName(ModuleHandle, ParentAppName, %MAX_PATH)       'Get Exe Path and Name
              105        ModuleHandle = GetModuleHandle("COSMOS")
              106        GetModuleFileName(ModuleHandle, ParentAppName, %MAX_PATH)       'Get Dll Path and Name
              107        REPLACE ".exe" WITH "" IN ParentAppName
              108        ParentAppName = ParentAppName + " - Error Log.log"          'Append string to show an error log
              109        SELECT CASE ErrFunc
              110             CASE 0                                                 'Function Failed
              111                  FUNCTION = ErrFunc
              112             CASE ELSE                                              'Function Passed
              113                  FUNCTION = %False
              114        END SELECT
                   END FUNCTION
              '*** Trace Last Error (if any)
                   FUNCTION TraceLastError(FunctionName AS STRING, LastErrorValue AS LONG, PbErrorValue AS LONG, OPTIONAL ErrorLineNumber AS LONG, OPTIONAL ErrorLineString AS STRING) AS LONG
              101       LOCAL LastError AS LONG
              102       LOCAL WhatToTrace AS STRING
              103       LOCAL ErrFunc AS LONG
              104       LOCAL DebugTraceRunning AS LONG
              105       LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH
              106       LOCAL OverRideError AS LONG
              107       ERR = PbErrorValue                                          'PB Clears ERR at the end of functions so to preserve it I reset it
              108       SELECT CASE ERR                                             'Is it a PB Error?
              109            CASE 0                                                 'Not a PB Error
              110                 FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %NULL, LastErrorValue, %NULL, ErrorBuff, SIZEOF(ErrorBuff), BYVAL %NULL     'Format the message
              111                 WhatToTrace = WhatToTrace + SPACE$(5) + "Unhandled WindowsError - " + STR$(LastErrorValue) + " - " + ErrorBuff + $CRLF
              112                 WhatToTrace = WhatToTrace + SPACE$(10) + " Function = " + FunctionName + $CRLF
              113                 WhatToTrace = WhatToTrace + SPACE$(10) + " at line: " + STR$(ErrorLineNumber) + $CRLF
                                  #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
              114                      WhatToTrace = WhatToTrace + SPACE$(10)+ " Last Executed: " + ErrorLineString
                                  #ENDIF
              115            CASE ELSE                                              'PB Error
              116                 LastError = ERR
              117                 WhatToTrace = WhatToTrace + SPACE$(5) + "Unhandled PbError # " + STR$(ERR) + " - " + ERROR$ + $CRLF
              118                 WhatToTrace = WhatToTrace + SPACE$(10) + " Function = " + FunctionName + $CRLF
              119                 WhatToTrace = WhatToTrace + SPACE$(10) + " at line: " + STR$(ErrorLineNumber)  + $CRLF
                                  #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
              120                      WhatToTrace = WhatToTrace + SPACE$(10)+ " Last Executed: " + ErrorLineString
                                  #ENDIF
              121       END SELECT
              122       TraceOn                                                     'If debugging then trace
              123       TracePrint WhatToTrace                               'If debugging then trace what?
              '*** Use one of the following to decide whether to continue or not
              '***      SetGetOverRideError(%NORESUME, OverRideError, %TRUE)        'Do not resume
              '***      SetGetOverRideError(%RESUME, OverRideError, %TRUE)          'Resume at same line that caused the error
              '***      SetGetOverRideError(%RESUMENEXT, OverRideError, %TRUE)      'Resume at line after the error
              124       SELECT CASE LastError
              125            CASE 0, %ERR_NOERROR                         'No Error
              126                 SetGetOverRideError(%RESUMENEXT, OverRideError, %TRUE)
              127            CASE 5, %ERR_ILLEGALFUNCTIONCALL             'Illegal function call
              128                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              129            CASE 6, %ERR_OVERFLOW                        'Overflow                '<---This error is not currently supported.
              130                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              131            CASE 7, %ERR_OUTOFMEMORY                     'Out of Memory
              132                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              133            CASE 9, %ERR_SUBSCRIPTPOINTEROUTOFRANGE      'Subscript / Pointer out of range
              134                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              135            CASE 11, %ERR_DIVISIONBYZERO                 'Division by zero         '<---This error is not currently supported.
              136                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              137            CASE 24, %ERR_DEVICETIMEOUT                  'Device TimeOut for UDP or TCP communications
              138                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              139            CASE 51, %ERR_INTERNALERROR                  'Internal Error
              140                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              141            CASE 52, %ERR_BADFILENAMEORNUMBER            'Bad File Name or Number '<--- Also used for Serial Port Errors
              142                 SetGetOverRideError(%RESUMENEXT, OverRideError, %TRUE)
              143            CASE 53, %ERR_FILENOTFOUND                   'File not found
              144                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              145            CASE 54, %ERR_BADFILEMODE                    'Bad File Mode
              146                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              147            CASE 55, %ERR_FILEISOPEN                     'File is already open    '<--- Also used for Serial Port Errors
              148                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              149            CASE 57, %ERR_DEVICEIOERROR                  'Device I/O Error        'Serial Port, TCP, UDP
              150                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              151            CASE 58, %ERR_FILEALREADYEXISTS              'File already exists
              152                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              153            CASE 61, %ERR_DISKFULL                       'Disk full
              154                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              155            CASE 62, %ERR_INPUTPASTEND                   'Input past end
              156                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              157            CASE 63, %ERR_BADRECORDNUMBER                'Bad record number
              158                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              159            CASE 64, %ERR_BADFILENAME                    'Bad file name
              160                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              161            CASE 67, %ERR_TOOMANYFILES                   'Too many files
              162                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              163            CASE 68, %ERR_DEVICEUNAVAILABLE              'Device unavailable
              164                 SetGetOverRideError(%RESUMENEXT, OverRideError, %TRUE)
              165            CASE 69, %ERR_COMMERROR                      'COMM Error         '<---Serial Port Error
              166                 SetGetOverRideError(%RESUMENEXT, OverRideError, %TRUE)
              167            CASE 70, %ERR_PERMISSIONDENIED               'Permission Denied
              168                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              169            CASE 71, %ERR_DISKNOTREADY                   'Disk not ready
              170                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              171            CASE 72, %ERR_DISKMEDIAERROR                 'Disk media error
              172                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              173            CASE 74, %ERR_RENAMEACROSSDISKS              'Rename across disks
              174                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              175            CASE 75, %ERR_PATHFILEACCESSERROR            'Path/File access error
              176                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              177            CASE 76, %ERR_PATHNOTFOUND                   'Path not found
              178                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              179            CASE 99, %ERR_OBJECTERROR                    'Object error
              180                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              181            CASE 241, %ERR_GLOBALMEMORYCORRUPT           'Global Memory Corrupt
              182                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              183            CASE 242, %ERR_STRINGSPACECORRUPT            'String space corrupt
              184                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
              185            CASE ELSE                                    'Either a 'Compile-Time' error (handled by PB) or Unknown what to do so just exit the function
              186       END SELECT
                   END FUNCTION
              '*** Print to trace file if debugging
                   FUNCTION TracePrint(WhatToPrint AS STRING) AS LONG
              101       TraceVariables                                              'Macro for common variables
              102       ErrFunc = SetGetDebugTraceRunning(%UNKNOWN_VALUE, DebugTraceRunning, %UNKNOWN_VALUE)      'Check if Debugging
              103       SELECT CASE DebugTraceRunning
              104            CASE 0                                                 'Not running a trace
              105                 FUNCTION = DebugTraceRunning
              106            CASE ELSE
              107                  TRACE ON
              108                 TRACE PRINT WhatToPrint                    '<--- Chose string since I do not know what is to be printed  for log file
              109                 FUNCTION = %FALSE
              110       END SELECT
              111       TraceUnHandledFunction                                              'Macro for Local Variables and Unhandled Errors
                   END FUNCTION
              '--------------------------------------------------------------------------------
              '*** Now for the DOOZYYYYyyyy....Handling GPF's and other major fatal errors
              '*** Commented fields are ones that I have no value for (yet) but MSDN say they exist
              '--------------------------------------------------------------------------------
                   FUNCTION TraceExceptionHandler(BYREF lpEP AS EXCEPTION_POINTERS) AS LONG
              101       STATIC TerminateInProcess AS LONG
              102       LOCAL ErrorRecord AS EXCEPTION_RECORD POINTER
              103       LOCAL ErrorCode AS LONG POINTER
              104       LOCAL WhatToTrace AS STRING
              105       LOCAL i AS LONG                                                  'For homing in on where the exception occurred
              106       LOCAL CallStackFunctions AS STRING                               'For homing in on where the exception occurred
              'MSGBOX FUNCNAME$ + $CR + "Event Fired" + $CR + STR$(TerminateInProcess) + str$(@ErrorRecord.ExceptionCode)
              107       SELECT CASE TerminateInProcess                              'If Unloading due to error let the OS handle it.
              108            CASE %TRUE
              109                 SetUnhandledExceptionFilter %EXCEPTION_EXECUTE_HANDLER 'Reactivate default Error Handler
              110                 RaiseException %NULL, %NULL, %NULL, %NULL              'Force normal Error Handler
              '*** Exit the thread (and application if this is the only thread)
              111                 ExitThread 0
              112            CASE %FALSE
              113                 TerminateInProcess = %TRUE
              114                 ErrorRecord = lpEP.pExceptionRecord                    'Detect the actual exception record
              115                 DO UNTIL @ErrorRecord.pExceptionRecord = 0             'Gather the exception record(s)
              116                      CALL MoveMemory(@ErrorRecord, @ErrorRecord.pExceptionRecord, SIZEOF(ErrorRecord))
              117                 LOOP
              118                 ErrorCode   = @ErrorRecord.ExceptionCode
              '*** Now we have in ErrorCode the ExceptionCode, that raised the crash, log the info
              119                 SELECT CASE ErrorCode
              120                      CASE %EXCEPTION_ACCESS_VIOLATION
              121                           WhatToTrace =   "ACCESS VIOLATION" + " <---> " + "The thread tried to read from or write to a virtual address for which it does not have the appropriate access"
              122                      CASE %EXCEPTION_ARRAY_BOUNDS_EXCEEDED
              123                           WhatToTrace =   "ARRAY BOUNDS EXCEEDED" + " <---> " + "The thread tried to access an array element that is out of bounds and the underlying hardware supports bounds checking."
              124                      CASE %EXCEPTION_BREAKPOINT
              125                           WhatToTrace = "BREAKPOINT" + " <---> " + "A breakpoint was encountered."
              126                      CASE %EXCEPTION_DATATYPE_MISALIGNMENT
              127                           WhatToTrace =   "DATATYPE MISALIGNMENT" + " <---> " + "The thread tried to read or write data that is misaligned on hardware that does not provide alignment. For example, 16-bit values must be aligned on 2-byte boundaries"
              128                      CASE %EXCEPTION_FLT_DENORMAL_OPERAND
              129                           WhatToTrace =  "FLOAT DENORMAL OPERAND" + " <---> " + "One of the operands in a floating-point operation is denormal. A denormal value is one that is too small to represent as a standard floating-point value."
              130                      CASE %EXCEPTION_FLT_DIVIDE_BY_ZERO
              131                           WhatToTrace =  "FLOAT DIVISION BY ZERO" + " <---> " + "The thread tried to divide a floating-point value by a floating-point divisor of zero."
              132                      CASE %EXCEPTION_FLT_INEXACT_RESULT
              133                           WhatToTrace =  "FLOAT INEXACT RESULT" + " <---> " + "The result of a floating-point operation cannot be represented exactly as a decimal fraction."
              134                      CASE %EXCEPTION_FLT_INVALID_OPERATION
              135                           WhatToTrace =  "FLOAT INVALID OPERATION" + " <---> " + "This exception represents any floating-point exception not included in this list."
              136                      CASE %EXCEPTION_FLT_OVERFLOW
              137                           WhatToTrace =  "FLOAT OVERFLOW" + " <---> " + "The exponent of a floating-point operation is greater than the magnitude allowed by the corresponding type."
              138                      CASE %EXCEPTION_FLT_STACK_CHECK
              139                           WhatToTrace =  "FLOAT STACK CHECK" + " <---> " + "The stack overflowed or underflowed as the result of a floating-point operation."
              140                      CASE %EXCEPTION_FLT_UNDERFLOW
              141                           WhatToTrace =  "FLOAT UNDERFLOW" + " <---> " + "The exponent of a floating-point operation is less than the magnitude allowed by the corresponding type."
              142                      CASE %EXCEPTION_ILLEGAL_INSTRUCTION
              143                           WhatToTrace =  "ILLEGAL INSTRUCTION" + " <---> " + "The thread tried to execute an invalid instruction."
              144                      CASE %EXCEPTION_IN_PAGE_ERROR
              145                           WhatToTrace = "IN PAGE ERROR" + " <---> "
              146                           WhatToTrace = WhatToTrace + "The thread tried to access a page that was not present, and the system was unable to load the page."
              147                           WhatToTrace = WhatToTrace + "For example, this exception might occur if a network connection is lost while running a program over "
              148                           WhatToTrace = WhatToTrace + "the network."
              149                      CASE %EXCEPTION_INT_DIVIDE_BY_ZERO
              151                           WhatToTrace =   "INTEGER DIVISION BY ZERO" + " <---> " + "The thread tried to divide an integer value by an integer divisor of zero."
              152                      CASE %EXCEPTION_INT_OVERFLOW
              153                           WhatToTrace =   "INTEGER OVERFLOW" + " <---> " + "The result of an integer operation caused a carry out of the most significant bit of the result."
              '154                      CASE %EXCEPTION_INVALID_DISPOSITION
              '155                           WhatToTrace =   "INVALID DISPOSITION" + " <---> " + "An exception handler returned an invalid disposition to the exception dispatcher. Programmers using a high-level language such as C should never encounter this exception."
              '156                      CASE %EXCEPTION_NONCONTINUABLE_EXCEPTION
              '157                           WhatToTrace =   "NONCONTINUABLE EXCEPTION" + " <---> " + "The thread tried to continue execution after a noncontinuable exception occurred."
              158                      CASE %EXCEPTION_PRIV_INSTRUCTION
              159                           WhatToTrace =   "PRIVATE INSTRUCTION" + " <---> " + "The thread tried to execute an instruction whose operation is not allowed in the current machine mode."
              160                      CASE %EXCEPTION_SINGLE_STEP
              161                           WhatToTrace =   "SINGLE STEP" + " <---> " + "A trace trap or other single-instruction mechanism signaled that one instruction has been executed."
              162                      CASE %EXCEPTION_STACK_OVERFLOW
              163                           WhatToTrace =  "STACK OVERFLOW" + " <---> " + "The thread used up its stack."
              164                      CASE ELSE
              165                           WhatToTrace =  CHR$(0)
              166                 END SELECT
              167                 FOR i = CALLSTKCOUNT TO 1 STEP -1
              168                      CallStackFunctions = CallStackFunctions + SPACE$(10) + CALLSTK$(i) + $CRLF
              169                 NEXT i
              '*** Code for writing a crash-log, save opened documents etc...
              170                 WhatToTrace = SPACE$(5) + "Unhandled WindowsException - " + STR$(@ErrorRecord.ExceptionCode) + " - " + WhatToTrace  + $CRLF + SPACE$(5) + " Function = " + CallStackFunctions + " at line: " + STR$(ERL)
              171                 TracePrint WhatToTrace
              '*** Exit the thread (and application if this is the only thread)
              172                 ExitThread 0                  'This will stop the typical "*.exe has encountered a problem and needs to close" error message to send a report to M$
              173       END SELECT
                   END FUNCTION
              #ENDIF
              ErrorHandling Demo
              Code:
              #COMPILE EXE                                                          'Compile as Executable
              #DIM ALL                                                              'Force all variables be declared
              #DEBUG ERROR OFF                                                      'Force all errors to be logged (including crashes)
              #TOOLS ON                                                             'Keep all Integrated tools turned on
              '--------------------------------------------------------------------------------
              '   ** Includes **
              '--------------------------------------------------------------------------------
              #INCLUDE "WIN32API.INC"                                               'Windows API routines
              #INCLUDE "ErrorHandling.inc"                                          'ErrorHandling routines
              '--------------------------------------------------------------------------------
              '--------------------------------------------------------------------------------
              '   ** Constants **
              '--------------------------------------------------------------------------------
              %IDD_DIALOG1                  = %WM_USER + 101                        'PbForms but I like to follow SDK Rules using %WM_USER
              %IDR_MENU1                    = %WM_USER + 102                        'PbForms but I like to follow SDK Rules using %WM_USER
              %IDM_DEBUG_DEBUGON            = %WM_USER + 1001                       'PbForms but I like to follow SDK Rules using %WM_USER
              %IDM_DEBUG_DEBUGOFF           = %WM_USER + 1002                       'PbForms but I like to follow SDK Rules using %WM_USER
              '--------------------------------------------------------------------------------
              '--------------------------------------------------------------------------------
              '   ** Declarations **
              '--------------------------------------------------------------------------------
              DECLARE FUNCTION PBMAIN()                                             'PbForms but I like to declare EVERYTHING
              DECLARE FUNCTION AttachMENU1(BYVAL hDlg AS DWORD) AS DWORD            'PbForms but I like to declare EVERYTHING
              DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()                           'PbForms but I like to declare EVERYTHING
              DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG          'PbForms but I like to declare EVERYTHING
              '--------------------------------------------------------------------------------
              '*** Now for the FUN Stuff
              '***      PB has 'On Error' for handling errors on the DDT side
              '***           PB can raise an error just by ERR = some number
              '***      Windows has 'GetLastError' to check any errors via SDK
              '***           Windows has to check for errors and handle them (errors are not raised)
              '***      Windows has "Exceptions" (You've seen them...the default usually shows the typical "*.exe has encountered a problem and needs to close" message)
              '***           Windows "Exceptions" can be raised, but default handler is typically fatal, but you can override that fatality
              '*** I REALLLLLLY want to know how to do the below without visibly inserting numbers but.....
              '***      PB Line numbers (if inserted) can assist in locating where an error occured (larger projects its smarter to contain line numbers to their functions)
              '***      PB FUNCNAME$ in conjunction with the line numbers can nail down what line the error occured on
              '***           Conjunction, junction, whats your function??? :-)
              '*** What makes it all work????
              '*** MACRO's baby, yeah baby yeah...(Finally got this one when larger code all had the same multiple commands and got tedious to type or copy/paste)
              '*** Globals.....Real Men don't need no stinkin Globals :-) (Finally got this one working deep with Windows API...See "Parameter as Reply" discussion)
              '--------------------------------------------------------------------------------
              FUNCTION PBMAIN()
              101       TraceVariables                                                   'Add To whatever function you want to debug
              102       LOCAL CommandLine AS STRING                                      'Variable for if CommandLine was passed to start program
              103       CommandLine = UCASE$(COMMAND$)                                   'Get the uppercase version of what the commandline is
              '*** METHOD 1 - LOG EVERYTHING (pass a commandline to auto-start either via commandline or shortcut with commandline commands)
              104       SELECT CASE CommandLine                                          'Check CommandLine  '<--- Is there a equivelent in API to COMMAND$????
              105            CASE "TRACE"                                                'If Trace then
              106                 StartTrace                                             'Start Tracing Routines
              107            CASE ELSE                                                   'If not then don't Trace till told to Trace
              108       END SELECT
              109       ShowDIALOG1 %HWND_DESKTOP                                       'PbForms function
              110       TraceUnHandledFunction                                                 'Macro for Local Variables and Unhandled Errors
              END FUNCTION
              '--------------------------------------------------------------------------------
              '--------------------------------------------------------------------------------
              '   ** Menus **
              '--------------------------------------------------------------------------------
              FUNCTION AttachMENU1(BYVAL hDlg AS DWORD) AS DWORD
              101       TraceVariables                                                   'Add To whatever function you want to debug (In this case most top-level possible)
              102       LOCAL hMenu AS DWORD
              103       LOCAL hPopUp1 AS DWORD
              104       MENU NEW BAR TO hMenu
              105       MENU NEW POPUP TO hPopUp1
              106       MENU ADD POPUP, hMenu, "Debug", hPopUp1, %MF_ENABLED
              107            MENU ADD STRING, hPopUp1, "Debug On", %IDM_DEBUG_DEBUGON, %MF_ENABLED
              108            MENU ADD STRING, hPopUp1, "Debug Off", %IDM_DEBUG_DEBUGOFF, %MF_ENABLED
              109       MENU ATTACH hMenu, hDlg
              110       FUNCTION = hMenu
              111       TraceUnHandledFunction                                                   'Macro for Local Variables and Unhandled Errors
              END FUNCTION
              '--------------------------------------------------------------------------------
              '--------------------------------------------------------------------------------
              '   ** CallBacks **
              '--------------------------------------------------------------------------------
              CALLBACK FUNCTION ShowDIALOG1Proc()
              101       TraceVariables                                                   'Add To whatever function you want to debug (In this case most top-level possible)
              102       SELECT CASE CBMSG
              103            CASE %WM_COMMAND
              104                 SELECT CASE CBCTL
              '*** For Run-Time Debugging of what you did not think of when originally writing your code
              105                      CASE %IDM_DEBUG_DEBUGON
              106                           StartTrace                                   'Start Tracing Functions
              '*** Comment or Uncomment for which ever test you want to try (I left the line numbers conflicting in case your dont comment or uncomment correctly)
              ''*** PB ON ERROR Test
              '107                          ERROR 52                                                         'Bogus Error for Demo
              107                           ERROR %ERR_COMMERROR
              MSGBOX "I continued", %MB_TASKMODAL
              
              ''*** Windows API Error Test
              '107                          SetLastError(6)                                                   'Bogus Error for Demo
              '108                          LastErrorCheck                                                    'Macro for checking last error
              ''*** Windows EXCEPTION Test
              '107                               RaiseException %EXCEPTION_BREAKPOINT, %NULL, %NULL, %NULL         'Bogus Fatal Error for Demo (or not fatal since I have control)
              109                      CASE %IDM_DEBUG_DEBUGOFF
              110                           EndTrace                                     'End Tracing Functions
              111                 END SELECT
              112       END SELECT
              113       TraceUnHandledFunction                                                   'Macro for Local Variables and Unhandled Errors
              MSGBOX "How? Did I get here? I should have continued at 108"
              END FUNCTION
              '--------------------------------------------------------------------------------
              '--------------------------------------------------------------------------------
              '   ** Dialogs **
              '--------------------------------------------------------------------------------
              FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
              101       TraceVariables                                                   'Add To whatever function you want to debug (In this case most top-level possible)
              102       LOCAL lRslt AS LONG
              103       LOCAL hDlg AS DWORD
              104       DIALOG NEW hParent, "Dialog1", 72, 132, 189, 114, %WS_POPUP OR %WS_BORDER OR _
                                  %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR _
                                  %WS_MAXIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR _
                                  %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_WINDOWEDGE OR _
                                  %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                                  %WS_EX_RIGHTSCROLLBAR, TO hDlg
              105       AttachMENU1 hDlg
              106       DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt            'Show Modal to give a chance to turn debugging on or off
              107       TraceUnHandledFunction                                                 'Macro for Local Variables and Unhandled Errors
              END FUNCTION
              '--------------------------------------------------------------------------------
              Can anyone spot where I am going wrong? I thought Resume Next would start at the line after the error??? not the line after checking whether to continue or exit???
              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? "

              Comment


              • #8
                Cliff,
                Try using
                ERR=0 : RESUME NEXT
                Instead of:
                ERRCLEAR : RESUME NEXT

                - It's a reported 'Issue' See: http://www.powerbasic.com/support/pb...ad.php?t=13459
                Rgds, Dave

                Comment


                • #9
                  It's not any sort of bug in the compiler, it's how it works. You may not execute a RESUME after the error trap ends.

                  Comment


                  • #10
                    Unless I am mis-reading, my RESUME is in my error handler.
                    I did change ErrClear to ERR = 0 and with that change my demo will close/crash/In Reality causes an Unhandled windows exception, that I was able to log.
                    The report was
                    Unhandled WindowsException - 3221225501 -
                    Function = PBMAIN()
                    SHOWDIALOG1(0)
                    SHOWDIALOG1PROC()
                    TRACEEXCEPTIONHANDLER(ðó<12><00><04>ô<12><00>)
                    at line: 0
                    However if I use ERRCLEAR then no crash, and no log of a windows exception.
                    I realize its not a bug, but I also realize that I do not understand well enough why ERRCLEAR <> ERR = 0, nor do I understand well enough Why RESUME NEXT resumes at the point after my error handler and not where the error happened?(or line after) so the code could continue with the error fixed????

                    Also, does anyone know what the unhandled windows exception 3221225501 even is???? I googled it, and it exists, but find no docs to what it is???

                    Update ---> Even not changing the value of ERR creates the same crash (So I must be on to something about PB Errors vs API Errors, and YES before someone mentions it, I know they are not equal *S*)
                    Last edited by Cliff Nichols; 2 Nov 2008, 04:57 PM. Reason: Update
                    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? "

                    Comment


                    • #11
                      NFS?
                      "Runtime Error nnn: RESUME without ERROR "

                      Just as in PB/DOS.

                      Except IIRC, you never set ERR yourself in your error handler, RESUME did that automatically.
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        Gee Cliff, I sure wish you had used more nested MACROs so I could be totally confused.

                        I would not be surprised if you have coded something where you could have a "RESUME without ERROR" error.

                        Does anyone have a "macro expander" which would, well, expand all MACROs so one might generate a "what the compiler actually sees" source code file?

                        I think that could be quite handy here.

                        MCM
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          I'm confused, Cliff. Just what exactly is your code supposed to do? I loaded and ran it, but nothing happens. I mean it compiles okay (at least no errors show) but that's it. No Dialogs, no windows, ...

                          I can even get it to show a MsgBox
                          Code:
                          Function PBMain()
                            ?"here",,FuncName$
                          101       TraceVariables                                                   'Add To whatever function you want to debug
                          102       Local CommandLine As String                                      'Variable for if CommandLine was passed to start program
                          103       CommandLine = UCase$(Command$)                                   'Get the uppercase version of what the commandline is
                          ...
                          or in
                          Code:
                          Function ShowDIALOG1(ByVal hParent As Dword) As Long
                            ?"here",,FuncName$
                          101       TraceVariables                                                   'Add To whatever function you want to debug (In this case most top-level possible)
                          102       Local lRslt As Long
                          It's a pretty day. I hope you enjoy it.

                          Gösta

                          JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                          LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                          Comment


                          • #14
                            PB shows Line Number at Error

                            Hi :
                            It would be great if PB of all versions showed the source line number where the error occurred, or close.
                            In the '70's I used a proprietary Business BASIC that did this, and it speeded up development time enormously.

                            PB prides themselves, and rightly so, on speed of compilation, but for me it is speed to getting the app to work that is important, and I would gladly trade a slower compile time and $$$ for this feature.

                            In my programs, I hardcode a Line Number and "IF ERR <> 0" at the top and bottom of every subroutine and function, and sprinkled liberally throughout the program. It may add a bit to the execution time, but PB is so fast, so what.
                            I also have Progress Messages with the Line Number throughout the program

                            If a user experiences a problem, I get a good idea where the error occurred.

                            Cheers
                            Hilton Schwartz

                            Comment


                            • #15
                              Just for MCM
                              Another version with no Macro's

                              ErrorHandling.bas
                              Code:
                              #COMPILE EXE                                                          'Compile as Executable
                              #DIM ALL                                                              'Force all variables be declared
                              #DEBUG ERROR OFF                                                      'Force all errors to be logged (including crashes)
                              #TOOLS ON                                                             'Keep all Integrated tools turned on
                              '--------------------------------------------------------------------------------
                              '   ** Includes **
                              '--------------------------------------------------------------------------------
                              #INCLUDE "WIN32API.INC"                                               'Windows API routines
                              '#INCLUDE "ErrorHandling.inc"                                          'ErrorHandling routines
                              #INCLUDE "ErrorHandlingNoMacro.inc"                                          'ErrorHandling routines
                              '--------------------------------------------------------------------------------
                              '--------------------------------------------------------------------------------
                              '   ** Constants **
                              '--------------------------------------------------------------------------------
                              %IDD_DIALOG1                  = %WM_USER + 101                        'PbForms but I like to follow SDK Rules using %WM_USER
                              %IDR_MENU1                    = %WM_USER + 102                        'PbForms but I like to follow SDK Rules using %WM_USER
                              %IDM_DEBUG_DEBUGON            = %WM_USER + 1001                       'PbForms but I like to follow SDK Rules using %WM_USER
                              %IDM_DEBUG_DEBUGOFF           = %WM_USER + 1002                       'PbForms but I like to follow SDK Rules using %WM_USER
                              '--------------------------------------------------------------------------------
                              '--------------------------------------------------------------------------------
                              '   ** Declarations **
                              '--------------------------------------------------------------------------------
                              DECLARE FUNCTION PBMAIN()                                             'PbForms but I like to declare EVERYTHING
                              DECLARE FUNCTION AttachMENU1(BYVAL hDlg AS DWORD) AS DWORD            'PbForms but I like to declare EVERYTHING
                              DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()                           'PbForms but I like to declare EVERYTHING
                              DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG          'PbForms but I like to declare EVERYTHING
                              '--------------------------------------------------------------------------------
                              '*** Now for the FUN Stuff
                              '***      PB has 'On Error' for handling errors on the DDT side
                              '***           PB can raise an error just by ERR = some number
                              '***      Windows has 'GetLastError' to check any errors via SDK
                              '***           Windows has to check for errors and handle them (errors are not raised)
                              '***      Windows has "Exceptions" (You've seen them...the default usually shows the typical "*.exe has encountered a problem and needs to close" message)
                              '***           Windows "Exceptions" can be raised, but default handler is typically fatal, but you can override that fatality
                              '*** I REALLLLLLY want to know how to do the below without visibly inserting numbers but.....
                              '***      PB Line numbers (if inserted) can assist in locating where an error occured (larger projects its smarter to contain line numbers to their functions)
                              '***      PB FUNCNAME$ in conjunction with the line numbers can nail down what line the error occured on
                              '***           Conjunction, junction, whats your function??? :-)
                              '*** What makes it all work????
                              '*** MACRO's baby, yeah baby yeah...(Finally got this one when larger code all had the same multiple commands and got tedious to type or copy/paste)
                              '*** Globals.....Real Men don't need no stinkin Globals :-) (Finally got this one working deep with Windows API...See "Parameter as Reply" discussion)
                              '--------------------------------------------------------------------------------
                              FUNCTION PBMAIN()
                              '101       TraceVariables                                                   'Add To whatever function you want to debug
                              1         ON ERROR GOTO ErrHandler                                    'Avoid using error numbers higher than 240, as they are reserved for use in critical error situations which can never be trapped with ON ERROR.
                              2         LOCAL DebugTraceRunning AS LONG                             'Variable for if debugging
                              3         LOCAL LastErrorValue AS LONG                                'Variable for GetLastError
                              4         LOCAL PbErrorValue AS LONG                                  'Variable for PB ERR
                              5         LOCAL ErrorLineNumber AS LONG                               'Variable for line number where the error occured (or the last checked line)
                              6         LOCAL ErrFunc AS LONG                                       'Variable for if there was an error in the function
                              7         LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH                       'Variable for Win32Api Error Description
                              8         LOCAL WhatToTrace AS STRING                                 'Variable for what to log for an error
                              9         LOCAL OverRideError AS LONG                                 'Variable for if to continue even if there is an error
                              10        SetLastError(0)                                             'Ensure the last Windows error is cleared
                              11        ERRCLEAR                                                    'Ensure the last PB error is cleared
                              '          SetUnhandledExceptionFilter %EXCEPTION_EXECUTE_HANDLER      '<--- Use this exception handler if wanting to use windows default (the typical "*.exe has encountered a problem and needs to close" message)
                              12        SetUnhandledExceptionFilter CODEPTR (TraceExceptionHandler) '<--- Use this exception handler if wanting to make a better crash-proof program
                              '
                              '
                              '
                              102       LOCAL CommandLine AS STRING                                      'Variable for if CommandLine was passed to start program
                              103       CommandLine = UCASE$(COMMAND$)                                   'Get the uppercase version of what the commandline is
                              '*** METHOD 1 - LOG EVERYTHING (pass a commandline to auto-start either via commandline or shortcut with commandline commands)
                              104       SELECT CASE CommandLine                                          'Check CommandLine  '<--- Is there a equivelent in API to COMMAND$????
                              105            CASE "TRACE"                                                'If Trace then
                              106                 StartTrace                                             'Start Tracing Routines
                              107            CASE ELSE                                                   'If not then don't Trace till told to Trace
                              108       END SELECT
                              109       ShowDIALOG1 %HWND_DESKTOP                                       'PbForms function
                              '110       TraceUnHandledFunction                                                 'Macro for Local Variables and Unhandled Errors
                              '
                              '
                              '
                                        EXIT FUNCTION
                              20   ErrHandler:
                              21        ErrFunc = GetLastError                                      'Get API Last Error
                                        #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL, ERL$
                                        #ELSEIF (%PB_REVISION) < &H900
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL
                                        #ENDIF
                              23        SetUnhandledExceptionFilter %NULL
                              '*** Mis-Reading documentation I thought I could Resume/ResumeNext, but this is not how it works
                              '***      So non of the below attempts work
                              24        SetGetOverRideError(%UNKNOWN_VALUE, OverRideError, %UNKNOWN_VALUE)
                              25        SELECT CASE OverRideError
                              26             CASE %RESUME, 0
                              27                  SetLastError(0)
                              28                  ERRCLEAR
                              29                  RESUME
                              30             CASE %RESUMENEXT, 1
                              31                  SetLastError(0)
                              '32                  ERRCLEAR
                              '32                  ERR = 0
                              33                  RESUME NEXT
                              34             CASE %NORESUME, -1
                              35        END SELECT
                              
                              END FUNCTION
                              '--------------------------------------------------------------------------------
                              '--------------------------------------------------------------------------------
                              '   ** Menus **
                              '--------------------------------------------------------------------------------
                              FUNCTION AttachMENU1(BYVAL hDlg AS DWORD) AS DWORD
                              '101       TraceVariables                                                   'Add To whatever function you want to debug (In this case most top-level possible)
                              1         ON ERROR GOTO ErrHandler                                    'Avoid using error numbers higher than 240, as they are reserved for use in critical error situations which can never be trapped with ON ERROR.
                              2         LOCAL DebugTraceRunning AS LONG                             'Variable for if debugging
                              3         LOCAL LastErrorValue AS LONG                                'Variable for GetLastError
                              4         LOCAL PbErrorValue AS LONG                                  'Variable for PB ERR
                              5         LOCAL ErrorLineNumber AS LONG                               'Variable for line number where the error occured (or the last checked line)
                              6         LOCAL ErrFunc AS LONG                                       'Variable for if there was an error in the function
                              7         LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH                       'Variable for Win32Api Error Description
                              8         LOCAL WhatToTrace AS STRING                                 'Variable for what to log for an error
                              9         LOCAL OverRideError AS LONG                                 'Variable for if to continue even if there is an error
                              10        SetLastError(0)                                             'Ensure the last Windows error is cleared
                              11        ERRCLEAR                                                    'Ensure the last PB error is cleared
                              '          SetUnhandledExceptionFilter %EXCEPTION_EXECUTE_HANDLER      '<--- Use this exception handler if wanting to use windows default (the typical "*.exe has encountered a problem and needs to close" message)
                              12        SetUnhandledExceptionFilter CODEPTR (TraceExceptionHandler) '<--- Use this exception handler if wanting to make a better crash-proof program
                              '
                              '
                              '
                              102       LOCAL hMenu AS DWORD
                              103       LOCAL hPopUp1 AS DWORD
                              104       MENU NEW BAR TO hMenu
                              105       MENU NEW POPUP TO hPopUp1
                              106       MENU ADD POPUP, hMenu, "Debug", hPopUp1, %MF_ENABLED
                              107            MENU ADD STRING, hPopUp1, "Debug On", %IDM_DEBUG_DEBUGON, %MF_ENABLED
                              108            MENU ADD STRING, hPopUp1, "Debug Off", %IDM_DEBUG_DEBUGOFF, %MF_ENABLED
                              109       MENU ATTACH hMenu, hDlg
                              110       FUNCTION = hMenu
                              '111       TraceUnHandledFunction                                                   'Macro for Local Variables and Unhandled Errors
                              '
                              '
                              '
                                        EXIT FUNCTION
                              20   ErrHandler:
                              21        ErrFunc = GetLastError                                      'Get API Last Error
                                        #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL, ERL$
                                        #ELSEIF (%PB_REVISION) < &H900
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL
                                        #ENDIF
                              23        SetUnhandledExceptionFilter %NULL
                              '*** Mis-Reading documentation I thought I could Resume/ResumeNext, but this is not how it works
                              '***      So non of the below attempts work
                              24        SetGetOverRideError(%UNKNOWN_VALUE, OverRideError, %UNKNOWN_VALUE)
                              25        SELECT CASE OverRideError
                              26             CASE %RESUME, 0
                              27                  SetLastError(0)
                              28                  ERRCLEAR
                              29                  RESUME
                              30             CASE %RESUMENEXT, 1
                              31                  SetLastError(0)
                              '32                  ERRCLEAR
                              '32                  ERR = 0
                              33                  RESUME NEXT
                              34             CASE %NORESUME, -1
                              35        END SELECT
                              END FUNCTION
                              '--------------------------------------------------------------------------------
                              '--------------------------------------------------------------------------------
                              '   ** CallBacks **
                              '--------------------------------------------------------------------------------
                              CALLBACK FUNCTION ShowDIALOG1Proc()
                              '101       TraceVariables                                                   'Add To whatever function you want to debug (In this case most top-level possible)
                              1         ON ERROR GOTO ErrHandler                                    'Avoid using error numbers higher than 240, as they are reserved for use in critical error situations which can never be trapped with ON ERROR.
                              2         LOCAL DebugTraceRunning AS LONG                             'Variable for if debugging
                              3         LOCAL LastErrorValue AS LONG                                'Variable for GetLastError
                              4         LOCAL PbErrorValue AS LONG                                  'Variable for PB ERR
                              5         LOCAL ErrorLineNumber AS LONG                               'Variable for line number where the error occured (or the last checked line)
                              6         LOCAL ErrFunc AS LONG                                       'Variable for if there was an error in the function
                              7         LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH                       'Variable for Win32Api Error Description
                              8         LOCAL WhatToTrace AS STRING                                 'Variable for what to log for an error
                              9         LOCAL OverRideError AS LONG                                 'Variable for if to continue even if there is an error
                              10        SetLastError(0)                                             'Ensure the last Windows error is cleared
                              11        ERRCLEAR                                                    'Ensure the last PB error is cleared
                              '          SetUnhandledExceptionFilter %EXCEPTION_EXECUTE_HANDLER      '<--- Use this exception handler if wanting to use windows default (the typical "*.exe has encountered a problem and needs to close" message)
                              12        SetUnhandledExceptionFilter CODEPTR (TraceExceptionHandler) '<--- Use this exception handler if wanting to make a better crash-proof program
                              '
                              '
                              '
                              102       SELECT CASE CBMSG
                              103            CASE %WM_COMMAND
                              104                 SELECT CASE CBCTL
                              '*** For Run-Time Debugging of what you did not think of when originally writing your code
                              105                      CASE %IDM_DEBUG_DEBUGON
                              106                           StartTrace                                   'Start Tracing Functions
                              '*** Comment or Uncomment for which ever test you want to try (I left the line numbers conflicting in case your dont comment or uncomment correctly)
                              ''*** PB ON ERROR Test
                              '107                          ERROR 52                                                         'Bogus Error for Demo
                              107                           ERROR %ERR_COMMERROR
                              MSGBOX "I Continued"
                              ''*** Windows API Error Test
                              '107                          SetLastError(6)                                                   'Bogus Error for Demo
                              '108                          LastErrorCheck                                                    'Macro for checking last error
                              ''*** Windows EXCEPTION Test
                              '107                               RaiseException %EXCEPTION_BREAKPOINT, %NULL, %NULL, %NULL         'Bogus Fatal Error for Demo (or not fatal since I have control)
                              109                      CASE %IDM_DEBUG_DEBUGOFF
                              110                           EndTrace                                     'End Tracing Functions
                              111                 END SELECT
                              112       END SELECT
                              '113       TraceUnHandledFunction                                                   'Macro for Local Variables and Unhandled Errors
                              '
                              '
                              '
                                        EXIT FUNCTION
                              20   ErrHandler:
                              21        ErrFunc = GetLastError                                      'Get API Last Error
                                        #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL, ERL$
                                        #ELSEIF (%PB_REVISION) < &H900
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL
                                        #ENDIF
                              23        SetUnhandledExceptionFilter %NULL
                              '*** Mis-Reading documentation I thought I could Resume/ResumeNext, but this is not how it works
                              '***      So non of the below attempts work
                              24        SetGetOverRideError(%UNKNOWN_VALUE, OverRideError, %UNKNOWN_VALUE)
                              25        SELECT CASE OverRideError
                              26             CASE %RESUME, 0
                              27                  SetLastError(0)
                              '28                  ERRCLEAR
                              29                  RESUME
                              30             CASE %RESUMENEXT, 1
                              31                  SetLastError(0)
                              '*** USE ERR = 0 to create crash, Use ERRCLEAR to only log error I purposely raised
                              '***      See ErrorHandling - Error Log.log for actual errors
                              '32                  ERRCLEAR
                              32                  ERR = 0
                              33                  RESUME NEXT
                              34             CASE %NORESUME, -1
                              35        END SELECT
                              MSGBOX "I Failed"
                              END FUNCTION
                              '--------------------------------------------------------------------------------
                              '--------------------------------------------------------------------------------
                              '   ** Dialogs **
                              '--------------------------------------------------------------------------------
                              FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                              '101       TraceVariables                                                   'Add To whatever function you want to debug (In this case most top-level possible)
                              1         ON ERROR GOTO ErrHandler                                    'Avoid using error numbers higher than 240, as they are reserved for use in critical error situations which can never be trapped with ON ERROR.
                              2         LOCAL DebugTraceRunning AS LONG                             'Variable for if debugging
                              3         LOCAL LastErrorValue AS LONG                                'Variable for GetLastError
                              4         LOCAL PbErrorValue AS LONG                                  'Variable for PB ERR
                              5         LOCAL ErrorLineNumber AS LONG                               'Variable for line number where the error occured (or the last checked line)
                              6         LOCAL ErrFunc AS LONG                                       'Variable for if there was an error in the function
                              7         LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH                       'Variable for Win32Api Error Description
                              8         LOCAL WhatToTrace AS STRING                                 'Variable for what to log for an error
                              9         LOCAL OverRideError AS LONG                                 'Variable for if to continue even if there is an error
                              10        SetLastError(0)                                             'Ensure the last Windows error is cleared
                              11        ERRCLEAR                                                    'Ensure the last PB error is cleared
                              '          SetUnhandledExceptionFilter %EXCEPTION_EXECUTE_HANDLER      '<--- Use this exception handler if wanting to use windows default (the typical "*.exe has encountered a problem and needs to close" message)
                              12        SetUnhandledExceptionFilter CODEPTR (TraceExceptionHandler) '<--- Use this exception handler if wanting to make a better crash-proof program
                              '
                              '
                              '
                              102       LOCAL lRslt AS LONG
                              103       LOCAL hDlg AS DWORD
                              104       DIALOG NEW hParent, "Dialog1", 72, 132, 189, 114, %WS_POPUP OR %WS_BORDER OR _
                                                  %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR _
                                                  %WS_MAXIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR _
                                                  %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_WINDOWEDGE OR _
                                                  %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                                                  %WS_EX_RIGHTSCROLLBAR, TO hDlg
                              105       AttachMENU1 hDlg
                              106       DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt            'Show Modal to give a chance to turn debugging on or off
                              '107       TraceUnHandledFunction                                                 'Macro for Local Variables and Unhandled Errors
                              '
                              '
                              '
                                        EXIT FUNCTION
                              20   ErrHandler:
                              21        ErrFunc = GetLastError                                      'Get API Last Error
                                        #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL, ERL$
                                        #ELSEIF (%PB_REVISION) < &H900
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL
                                        #ENDIF
                              23        SetUnhandledExceptionFilter %NULL
                              '*** Mis-Reading documentation I thought I could Resume/ResumeNext, but this is not how it works
                              '***      So non of the below attempts work
                              24        SetGetOverRideError(%UNKNOWN_VALUE, OverRideError, %UNKNOWN_VALUE)
                              25        SELECT CASE OverRideError
                              26             CASE %RESUME, 0
                              27                  SetLastError(0)
                              28                  ERRCLEAR
                              29                  RESUME
                              30             CASE %RESUMENEXT, 1
                              31                  SetLastError(0)
                              '32                  ERRCLEAR
                              '32                  ERR = 0
                              33                  RESUME NEXT
                              34             CASE %NORESUME, -1
                              35        END SELECT
                              
                              END FUNCTION
                              '--------------------------------------------------------------------------------
                              ErrorHandling.inc
                              Code:
                              '*** ErrorHandling.inc
                              '***      Written by: Cliff Nichols - 08-28-2008
                              '***      Modified by: Cliff Nichols - 11-01-2008
                              '***      Compiler: 8.04/9.0
                              '***      Should work on: 7/8/9
                              '***      Tested on: XP-Pro SP3, Vista-Ultimate
                              '***      Should work on: 95/98/ME/NT/2K/XP/Vista
                              '***      Purpose - Beefed up Error Handling Routines to attempt to "Bullet-Proof" apps
                              '*** Usage:
                              '***      StartTrace - Create a Trace log file
                              '***      TraceVariables - Common Variables for each function
                              '***
                              '***      TraceUnHandledFunction - Steps for anything that you did not think of when writing and testing your code
                              '--------------------------------------------------------------------------------
                              '*** Now for the FUN Stuff
                              '***      PB has 'On Error' for handling errors on the DDT side
                              '***           PB can raise an error just by ERR = some number
                              '***      Windows has 'GetLastError' to check any errors via SDK
                              '***           Windows has to check for errors and handle them (errors are not raised)
                              '***      Windows has "Exceptions" (You've seen them...the default usually shows the typical "*.exe has encountered a problem and needs to close" message)
                              '***           Windows "Exceptions" can be raised, but default handler is typically fatal, but you can override that fatality
                              '*** I REALLLLLLY want to know how to do the below without visibly inserting numbers but.....
                              '***      PB Line numbers (if inserted) can assist in locating where an error occured (larger projects its smarter to contain line numbers to their functions)
                              '***      PB FUNCNAME$ in conjunction with the line numbers can nail down what line the error occured on
                              '***           Conjunction, junction, whats your function??? :-)
                              '*** What makes it all work????
                              '*** MACRO's baby, yeah baby yeah...(Finally got this one when larger code all had the same multiple commands and got tedious to type or copy/paste)
                              '*** Globals.....Real Men don't need no stinkin Globals :-) (Finally got this one working deep with Windows API...See "Parameter as Reply" discussion)
                              '***
                              '***
                              '*** 11-01-08
                              '***      Added line numbers to everything so line numbers for functions/subs/macros should start at 100 and up for future use of added macros
                              '--------------------------------------------------------------------------------
                              
                              '*** If not already declared in your code, then declare this INC
                              #IF NOT %DEF(%ERRORHANDLING)
                                   %ERRORHANDLING = 1
                              '*** Globals
                              '***      NONE
                              '***           - Use SetGetDebugTraceRunning to keep value in replacement for a global DebugTraceRunning
                              '***           - Use SetGetLastFunction to keep value in replacement for a global LastFunction
                              '*** Constants
                                   %UNKNOWN_VALUE = -1
                                   %RESUME = 0
                                   %RESUMENEXT = 1
                                   %NORESUME = -1
                              '*** Constants not found in Win32Api.Inc
                                   %EXCEPTION_ILLEGAL_INSTRUCTION  = &HC000001D
                                   %EXCEPTION_STACK_OVERFLOW       = &HC00000FD
                              '*************************************************************************************************************
                              '*** Macro's - When Compiled, replace the name of the macro with all the functions and processes in the macro
                              '***           As if you had done it yourself in each and every SUB/FUNCTION it was called
                              '***           Do not add line numbers to Macro's unless you want to renumber functions that use the macros
                              '*************************************************************************************************************
                              '*** TraceUnHandledFunction
                              '***      Macro to replace code at the end of each function being being debugged
                              '***           Code will jump to end ON ERROR or if told to jump to end
                              '***           Code relies on TraceVariables to compile
                              '***                11-01-08 Added Macros to work with Functions/Subs/Methods
                              '*************************************************************************************************************
                              '*** Function
                              
                              '*************************************************************************************************************
                              '*** NOW FOR THE STANDARD INC SETUP
                              '*************************************************************************************************************
                              '*** Declares:
                                   DECLARE FUNCTION SetGetDebugTraceRunning(ValueToSet AS LONG, ValueResults AS LONG, ResetValue AS LONG) AS LONG
                                   DECLARE FUNCTION SetGetLastFunction(ValueToSet AS STRING, ValueResults AS STRING, ResetValue AS LONG) AS LONG
                                   DECLARE FUNCTION SetGetOverRideError(ValueToSet AS LONG, ValueResults AS LONG, ResetValue AS LONG) AS LONG
                                   DECLARE FUNCTION StartTrace ALIAS "StartTrace"() AS LONG
                                   DECLARE FUNCTION EndTrace ALIAS "EndTrace"() AS LONG
                                   DECLARE FUNCTION TraceProgramName(ParentAppName AS ASCIIZ * %MAX_PATH) AS LONG
                                   DECLARE FUNCTION TraceLastError(FunctionName AS STRING, LastErrorValue AS LONG, PbErrorValue AS LONG, OPTIONAL ErrorLineNumber AS LONG, OPTIONAL ErrorLineString AS STRING) AS LONG
                                   DECLARE FUNCTION TracePrint(WhatToTrace AS STRING) AS LONG
                                   DECLARE FUNCTION TraceExceptionHandler(BYREF lpEP AS EXCEPTION_POINTERS) AS LONG
                              '*** Dependant Inc Files:
                              '***      None
                              '*** Functions:
                              '***      SetGetDebugTraceRunning Replaces the need for global variables so that local variables in other functions are easier to read
                                   FUNCTION SetGetDebugTraceRunning(ValueToSet AS LONG, ValueResults AS LONG, ResetValue AS LONG) AS LONG
                              '101       TraceVariables                                                   'Add To whatever function you want to debug (In this case most top-level possible)
                              1         ON ERROR GOTO ErrHandler                                    'Avoid using error numbers higher than 240, as they are reserved for use in critical error situations which can never be trapped with ON ERROR.
                              2         LOCAL DebugTraceRunning AS LONG                             'Variable for if debugging
                              3         LOCAL LastErrorValue AS LONG                                'Variable for GetLastError
                              4         LOCAL PbErrorValue AS LONG                                  'Variable for PB ERR
                              5         LOCAL ErrorLineNumber AS LONG                               'Variable for line number where the error occured (or the last checked line)
                              6         LOCAL ErrFunc AS LONG                                       'Variable for if there was an error in the function
                              7         LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH                       'Variable for Win32Api Error Description
                              8         LOCAL WhatToTrace AS STRING                                 'Variable for what to log for an error
                              9         LOCAL OverRideError AS LONG                                 'Variable for if to continue even if there is an error
                              10        SetLastError(0)                                             'Ensure the last Windows error is cleared
                              11        ERRCLEAR                                                    'Ensure the last PB error is cleared
                              '          SetUnhandledExceptionFilter %EXCEPTION_EXECUTE_HANDLER      '<--- Use this exception handler if wanting to use windows default (the typical "*.exe has encountered a problem and needs to close" message)
                              12        SetUnhandledExceptionFilter CODEPTR (TraceExceptionHandler) '<--- Use this exception handler if wanting to make a better crash-proof program
                              '
                              '
                              '
                              102       STATIC FunctionValue AS LONG                                'Static to hold current value
                              103       SELECT CASE ResetValue                                      'Decide whether to Set or to Get the current value
                              104            CASE %False, %UNKNOWN_VALUE                            'If set to False, or -1 Then Get Current Value
                              105                 ValueResults = FunctionValue                      'Return Results as a parameter
                              106            CASE = %TRUE                                           'If set to True then Reset the Current Value
                              107                 FunctionValue = ValueToSet                        'Reset the value
                              108                 ValueResults = FunctionValue                      'Return Results as a parameter
                              109       END SELECT
                              110      FUNCTION = %False                                           'Return if Function Failed
                              '111      TraceUnHandledFunction                                              'Exit Function or handle unhandled errors
                              '
                              '
                              '
                                        EXIT FUNCTION
                              20   ErrHandler:
                              21        ErrFunc = GetLastError                                      'Get API Last Error
                                        #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL, ERL$
                                        #ELSEIF (%PB_REVISION) < &H900
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL
                                        #ENDIF
                              23        SetUnhandledExceptionFilter %NULL
                              '*** Mis-Reading documentation I thought I could Resume/ResumeNext, but this is not how it works
                              '***      So non of the below attempts work
                              24        SetGetOverRideError(%UNKNOWN_VALUE, OverRideError, %UNKNOWN_VALUE)
                              25        SELECT CASE OverRideError
                              26             CASE %RESUME, 0
                              27                  SetLastError(0)
                              28                  ERRCLEAR
                              29                  RESUME
                              30             CASE %RESUMENEXT, 1
                              31                  SetLastError(0)
                              '32                  ERRCLEAR
                              '32                  ERR = 0
                              33                  RESUME NEXT
                              34             CASE %NORESUME, -1
                              35        END SELECT
                                   END FUNCTION
                              '*** SetGetLastFunction Replaces the need for global variables so that local variables in other functions are easier to read
                                   FUNCTION SetGetLastFunction(ValueToSet AS STRING, ValueResults AS STRING, ResetValue AS LONG) AS LONG
                              '101       TraceVariables                                                   'Add To whatever function you want to debug (In this case most top-level possible)
                              1         ON ERROR GOTO ErrHandler                                    'Avoid using error numbers higher than 240, as they are reserved for use in critical error situations which can never be trapped with ON ERROR.
                              2         LOCAL DebugTraceRunning AS LONG                             'Variable for if debugging
                              3         LOCAL LastErrorValue AS LONG                                'Variable for GetLastError
                              4         LOCAL PbErrorValue AS LONG                                  'Variable for PB ERR
                              5         LOCAL ErrorLineNumber AS LONG                               'Variable for line number where the error occured (or the last checked line)
                              6         LOCAL ErrFunc AS LONG                                       'Variable for if there was an error in the function
                              7         LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH                       'Variable for Win32Api Error Description
                              8         LOCAL WhatToTrace AS STRING                                 'Variable for what to log for an error
                              9         LOCAL OverRideError AS LONG                                 'Variable for if to continue even if there is an error
                              10        SetLastError(0)                                             'Ensure the last Windows error is cleared
                              11        ERRCLEAR                                                    'Ensure the last PB error is cleared
                              '          SetUnhandledExceptionFilter %EXCEPTION_EXECUTE_HANDLER      '<--- Use this exception handler if wanting to use windows default (the typical "*.exe has encountered a problem and needs to close" message)
                              12        SetUnhandledExceptionFilter CODEPTR (TraceExceptionHandler) '<--- Use this exception handler if wanting to make a better crash-proof program
                              '
                              '
                              '
                              102       STATIC FunctionValue AS STRING                              'Static to hold current value
                              103       SELECT CASE ResetValue                                      'Decide whether to Set or to Get the current value
                              104            CASE %False, %UNKNOWN_VALUE                            'If set to False, or -1 Then Get Current Value
                              105                 ValueResults = FunctionValue                      'Return Results as a parameter
                              106            CASE = %TRUE                                           'If set to True then Reset the Current Value
                              107                 FunctionValue = ValueToSet                        'Reset the value
                              108                 ValueResults = FunctionValue                      'Return Results as a parameter
                              109       END SELECT
                              110       FUNCTION = %False                                           'Return if Function Failed
                              '111       TraceUnHandledFunction                                              'Exit Function or handle unhandled errors
                              '
                              '
                              '
                                        EXIT FUNCTION
                              20   ErrHandler:
                              21        ErrFunc = GetLastError                                      'Get API Last Error
                                        #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL, ERL$
                                        #ELSEIF (%PB_REVISION) < &H900
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL
                                        #ENDIF
                              23        SetUnhandledExceptionFilter %NULL
                              '*** Mis-Reading documentation I thought I could Resume/ResumeNext, but this is not how it works
                              '***      So non of the below attempts work
                              24        SetGetOverRideError(%UNKNOWN_VALUE, OverRideError, %UNKNOWN_VALUE)
                              25        SELECT CASE OverRideError
                              26             CASE %RESUME, 0
                              27                  SetLastError(0)
                              28                  ERRCLEAR
                              29                  RESUME
                              30             CASE %RESUMENEXT, 1
                              31                  SetLastError(0)
                              '32                  ERRCLEAR
                              '32                  ERR = 0
                              33                  RESUME NEXT
                              34             CASE %NORESUME, -1
                              35        END SELECT
                                   END FUNCTION
                              '*** SetGetOverRideError Replaces the need for global variables so that local variables in other functions are easier to read
                                   FUNCTION SetGetOverRideError(ValueToSet AS LONG, ValueResults AS LONG, ResetValue AS LONG) AS LONG
                              '101       TraceVariables                                                   'Add To whatever function you want to debug (In this case most top-level possible)
                              1         ON ERROR GOTO ErrHandler                                    'Avoid using error numbers higher than 240, as they are reserved for use in critical error situations which can never be trapped with ON ERROR.
                              2         LOCAL DebugTraceRunning AS LONG                             'Variable for if debugging
                              3         LOCAL LastErrorValue AS LONG                                'Variable for GetLastError
                              4         LOCAL PbErrorValue AS LONG                                  'Variable for PB ERR
                              5         LOCAL ErrorLineNumber AS LONG                               'Variable for line number where the error occured (or the last checked line)
                              6         LOCAL ErrFunc AS LONG                                       'Variable for if there was an error in the function
                              7         LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH                       'Variable for Win32Api Error Description
                              8         LOCAL WhatToTrace AS STRING                                 'Variable for what to log for an error
                              9         LOCAL OverRideError AS LONG                                 'Variable for if to continue even if there is an error
                              10        SetLastError(0)                                             'Ensure the last Windows error is cleared
                              11        ERRCLEAR                                                    'Ensure the last PB error is cleared
                              '          SetUnhandledExceptionFilter %EXCEPTION_EXECUTE_HANDLER      '<--- Use this exception handler if wanting to use windows default (the typical "*.exe has encountered a problem and needs to close" message)
                              12        SetUnhandledExceptionFilter CODEPTR (TraceExceptionHandler) '<--- Use this exception handler if wanting to make a better crash-proof program
                              '
                              '
                              '
                              102       STATIC FunctionValue AS LONG                              'Static to hold current value
                              103       SELECT CASE ResetValue                                      'Decide whether to Set or to Get the current value
                              104            CASE %False, %UNKNOWN_VALUE                            'If set to False, or -1 Then Get Current Value
                              105                 ValueResults = FunctionValue                      'Return Results as a parameter
                              106            CASE = %TRUE                                           'If set to True then Reset the Current Value
                              107                 FunctionValue = ValueToSet                        'Reset the value
                              108                 ValueResults = FunctionValue                      'Return Results as a parameter
                              109       END SELECT
                              110       FUNCTION = %False                                           'Return if Function Failed
                              '111       TraceUnHandledFunction                                              'Exit Function or handle unhandled errors
                              '
                              '
                              '
                                        EXIT FUNCTION
                              20   ErrHandler:
                              21        ErrFunc = GetLastError                                      'Get API Last Error
                                        #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL, ERL$
                                        #ELSEIF (%PB_REVISION) < &H900
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL
                                        #ENDIF
                              23        SetUnhandledExceptionFilter %NULL
                              '*** Mis-Reading documentation I thought I could Resume/ResumeNext, but this is not how it works
                              '***      So non of the below attempts work
                              24        SetGetOverRideError(%UNKNOWN_VALUE, OverRideError, %UNKNOWN_VALUE)
                              25        SELECT CASE OverRideError
                              26             CASE %RESUME, 0
                              27                  SetLastError(0)
                              28                  ERRCLEAR
                              29                  RESUME
                              30             CASE %RESUMENEXT, 1
                              31                  SetLastError(0)
                              '32                  ERRCLEAR
                              '32                  ERR = 0
                              33                  RESUME NEXT
                              34             CASE %NORESUME, -1
                              35        END SELECT
                                   END FUNCTION
                              '*** Start Tracing
                                   FUNCTION StartTrace ALIAS "StartTrace"() EXPORT AS LONG
                              '101       TraceVariables                                                   'Add To whatever function you want to debug (In this case most top-level possible)
                              1         ON ERROR GOTO ErrHandler                                    'Avoid using error numbers higher than 240, as they are reserved for use in critical error situations which can never be trapped with ON ERROR.
                              2         LOCAL DebugTraceRunning AS LONG                             'Variable for if debugging
                              3         LOCAL LastErrorValue AS LONG                                'Variable for GetLastError
                              4         LOCAL PbErrorValue AS LONG                                  'Variable for PB ERR
                              5         LOCAL ErrorLineNumber AS LONG                               'Variable for line number where the error occured (or the last checked line)
                              6         LOCAL ErrFunc AS LONG                                       'Variable for if there was an error in the function
                              7         LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH                       'Variable for Win32Api Error Description
                              8         LOCAL WhatToTrace AS STRING                                 'Variable for what to log for an error
                              9         LOCAL OverRideError AS LONG                                 'Variable for if to continue even if there is an error
                              10        SetLastError(0)                                             'Ensure the last Windows error is cleared
                              11        ERRCLEAR                                                    'Ensure the last PB error is cleared
                              '          SetUnhandledExceptionFilter %EXCEPTION_EXECUTE_HANDLER      '<--- Use this exception handler if wanting to use windows default (the typical "*.exe has encountered a problem and needs to close" message)
                              12        SetUnhandledExceptionFilter CODEPTR (TraceExceptionHandler) '<--- Use this exception handler if wanting to make a better crash-proof program
                              '
                              '
                              '
                              102       LOCAL TraceLogName AS ASCIIZ * %MAX_PATH
                              103       ErrFunc = TraceProgramName(TraceLogName)                    'Get a trace log name
                              104       SELECT CASE ErrFunc                                         'If no error creating the log
                              105            CASE %FALSE
                              106                 DebugTraceRunning = %TRUE                         'Set variable for if tracing
                              107                 TRACE NEW TraceLogName                            'Create the log
                              108            CASE ELSE                                              'Some Error Occurred
                              109       END SELECT
                              110       ErrFunc = SetGetDebugTraceRunning(%TRUE, DebugTraceRunning, %TRUE)    'Set the flag that we are tracing
                              '111       TraceUnHandledFunction                                              'Macro for Local Variables and Unhandled Errors
                              '
                              '
                              '
                                        EXIT FUNCTION
                              20   ErrHandler:
                              21        ErrFunc = GetLastError                                      'Get API Last Error
                                        #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL, ERL$
                                        #ELSEIF (%PB_REVISION) < &H900
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL
                                        #ENDIF
                              23        SetUnhandledExceptionFilter %NULL
                              '*** Mis-Reading documentation I thought I could Resume/ResumeNext, but this is not how it works
                              '***      So non of the below attempts work
                              24        SetGetOverRideError(%UNKNOWN_VALUE, OverRideError, %UNKNOWN_VALUE)
                              25        SELECT CASE OverRideError
                              26             CASE %RESUME, 0
                              27                  SetLastError(0)
                              28                  ERRCLEAR
                              29                  RESUME
                              30             CASE %RESUMENEXT, 1
                              31                  SetLastError(0)
                              '32                  ERRCLEAR
                              '32                  ERR = 0
                              33                  RESUME NEXT
                              34             CASE %NORESUME, -1
                              35        END SELECT
                                   END FUNCTION
                              '*** End Tracing
                                   FUNCTION EndTrace ALIAS "EndTrace"() EXPORT AS LONG
                              '101       TraceVariables                                                   'Add To whatever function you want to debug (In this case most top-level possible)
                              1         ON ERROR GOTO ErrHandler                                    'Avoid using error numbers higher than 240, as they are reserved for use in critical error situations which can never be trapped with ON ERROR.
                              2         LOCAL DebugTraceRunning AS LONG                             'Variable for if debugging
                              3         LOCAL LastErrorValue AS LONG                                'Variable for GetLastError
                              4         LOCAL PbErrorValue AS LONG                                  'Variable for PB ERR
                              5         LOCAL ErrorLineNumber AS LONG                               'Variable for line number where the error occured (or the last checked line)
                              6         LOCAL ErrFunc AS LONG                                       'Variable for if there was an error in the function
                              7         LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH                       'Variable for Win32Api Error Description
                              8         LOCAL WhatToTrace AS STRING                                 'Variable for what to log for an error
                              9         LOCAL OverRideError AS LONG                                 'Variable for if to continue even if there is an error
                              10        SetLastError(0)                                             'Ensure the last Windows error is cleared
                              11        ERRCLEAR                                                    'Ensure the last PB error is cleared
                              '          SetUnhandledExceptionFilter %EXCEPTION_EXECUTE_HANDLER      '<--- Use this exception handler if wanting to use windows default (the typical "*.exe has encountered a problem and needs to close" message)
                              12        SetUnhandledExceptionFilter CODEPTR (TraceExceptionHandler) '<--- Use this exception handler if wanting to make a better crash-proof program
                              '
                              '
                              '
                              102        LOCAL TraceLogName AS ASCIIZ * %MAX_PATH
                              103        ErrFunc = TraceProgramName(TraceLogName)                   'Get a trace log name
                              104        SELECT CASE ErrFunc                                        'If the trace log name exists (no error) then
                              105             CASE %FALSE
                              106                  DebugTraceRunning = %FALSE
                              107                  TRACE CLOSE                                      'Close Trace File
                              108             CASE ELSE                                             'Some Error Occurred
                              109        END SELECT
                              110        ErrFunc = SetGetDebugTraceRunning(%FALSE, DebugTraceRunning, %TRUE)      'Set the flag for we are no longer tracing
                              '111        TraceUnHandledFunction                                            'Macro for Local Variables and Unhandled Errors
                              '
                              '
                              '
                                        EXIT FUNCTION
                              20   ErrHandler:
                              21        ErrFunc = GetLastError                                      'Get API Last Error
                                        #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL, ERL$
                                        #ELSEIF (%PB_REVISION) < &H900
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL
                                        #ENDIF
                              23        SetUnhandledExceptionFilter %NULL
                              '*** Mis-Reading documentation I thought I could Resume/ResumeNext, but this is not how it works
                              '***      So non of the below attempts work
                              24        SetGetOverRideError(%UNKNOWN_VALUE, OverRideError, %UNKNOWN_VALUE)
                              25        SELECT CASE OverRideError
                              26             CASE %RESUME, 0
                              27                  SetLastError(0)
                              28                  ERRCLEAR
                              29                  RESUME
                              30             CASE %RESUMENEXT, 1
                              31                  SetLastError(0)
                              '32                  ERRCLEAR
                              '32                  ERR = 0
                              33                  RESUME NEXT
                              34             CASE %NORESUME, -1
                              35        END SELECT
                                   END FUNCTION
                              '*** Set up a log file name
                                   FUNCTION TraceProgramName(ParentAppName AS ASCIIZ * %MAX_PATH) AS LONG
                              '101       TraceVariables                                                   'Add To whatever function you want to debug (In this case most top-level possible)
                              1         ON ERROR GOTO ErrHandler                                    'Avoid using error numbers higher than 240, as they are reserved for use in critical error situations which can never be trapped with ON ERROR.
                              2         LOCAL DebugTraceRunning AS LONG                             'Variable for if debugging
                              3         LOCAL LastErrorValue AS LONG                                'Variable for GetLastError
                              4         LOCAL PbErrorValue AS LONG                                  'Variable for PB ERR
                              5         LOCAL ErrorLineNumber AS LONG                               'Variable for line number where the error occured (or the last checked line)
                              6         LOCAL ErrFunc AS LONG                                       'Variable for if there was an error in the function
                              7         LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH                       'Variable for Win32Api Error Description
                              8         LOCAL WhatToTrace AS STRING                                 'Variable for what to log for an error
                              9         LOCAL OverRideError AS LONG                                 'Variable for if to continue even if there is an error
                              10        SetLastError(0)                                             'Ensure the last Windows error is cleared
                              11        ERRCLEAR                                                    'Ensure the last PB error is cleared
                              '          SetUnhandledExceptionFilter %EXCEPTION_EXECUTE_HANDLER      '<--- Use this exception handler if wanting to use windows default (the typical "*.exe has encountered a problem and needs to close" message)
                              12        SetUnhandledExceptionFilter CODEPTR (TraceExceptionHandler) '<--- Use this exception handler if wanting to make a better crash-proof program
                              '
                              '
                              '
                              '101        LOCAL ErrFunc AS LONG
                              102        LOCAL ModuleHandle AS DWORD
                              '102        ErrFunc = GetModuleFileName(GetModuleHandle(BYVAL %NULL), ParentAppName, %MAX_PATH)       'Returns current path to owning parent
                              '103        ParentAppName = MID$(ParentAppName, 1, INSTR(ParentAppName, ".exe") - 1)  'Strip all but the parent '.exe' part
                              103        ModuleHandle = GetModuleHandle($NUL)
                              104        GetModuleFileName(ModuleHandle, ParentAppName, %MAX_PATH)       'Get Exe Path and Name
                              '105        ModuleHandle = GetModuleHandle("COSMOS")
                              '106        GetModuleFileName(ModuleHandle, ParentAppName, %MAX_PATH)       'Get Dll Path and Name
                              107        REPLACE ".exe" WITH "" IN ParentAppName
                              108        ParentAppName = ParentAppName + " - Error Log.log"          'Append string to show an error log
                              109        SELECT CASE ErrFunc
                              110             CASE 0                                                 'Function Failed
                              111                  FUNCTION = ErrFunc
                              112             CASE ELSE                                              'Function Passed
                              113                  FUNCTION = %False
                              114        END SELECT
                              '
                              '
                              '
                                        EXIT FUNCTION
                              20   ErrHandler:
                              21        ErrFunc = GetLastError                                      'Get API Last Error
                                        #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL, ERL$
                                        #ELSEIF (%PB_REVISION) < &H900
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL
                                        #ENDIF
                              23        SetUnhandledExceptionFilter %NULL
                              '*** Mis-Reading documentation I thought I could Resume/ResumeNext, but this is not how it works
                              '***      So non of the below attempts work
                              24        SetGetOverRideError(%UNKNOWN_VALUE, OverRideError, %UNKNOWN_VALUE)
                              25        SELECT CASE OverRideError
                              26             CASE %RESUME, 0
                              27                  SetLastError(0)
                              28                  ERRCLEAR
                              29                  RESUME
                              30             CASE %RESUMENEXT, 1
                              31                  SetLastError(0)
                              '32                  ERRCLEAR
                              '32                  ERR = 0
                              33                  RESUME NEXT
                              34             CASE %NORESUME, -1
                              35        END SELECT
                                   END FUNCTION
                              '*** Trace Last Error (if any)
                                   FUNCTION TraceLastError(FunctionName AS STRING, LastErrorValue AS LONG, PbErrorValue AS LONG, OPTIONAL ErrorLineNumber AS LONG, OPTIONAL ErrorLineString AS STRING) AS LONG
                              '101       TraceVariables                                                   'Add To whatever function you want to debug (In this case most top-level possible)
                              1         ON ERROR GOTO ErrHandler                                    'Avoid using error numbers higher than 240, as they are reserved for use in critical error situations which can never be trapped with ON ERROR.
                              2         LOCAL DebugTraceRunning AS LONG                             'Variable for if debugging
                              '3         LOCAL LastErrorValue AS LONG                                'Variable for GetLastError
                              '4         LOCAL PbErrorValue AS LONG                                  'Variable for PB ERR
                              '5         LOCAL ErrorLineNumber AS LONG                               'Variable for line number where the error occured (or the last checked line)
                              6         LOCAL ErrFunc AS LONG                                       'Variable for if there was an error in the function
                              7         LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH                       'Variable for Win32Api Error Description
                              8         LOCAL WhatToTrace AS STRING                                 'Variable for what to log for an error
                              9         LOCAL OverRideError AS LONG                                 'Variable for if to continue even if there is an error
                              10        SetLastError(0)                                             'Ensure the last Windows error is cleared
                              11        ERRCLEAR                                                    'Ensure the last PB error is cleared
                              '          SetUnhandledExceptionFilter %EXCEPTION_EXECUTE_HANDLER      '<--- Use this exception handler if wanting to use windows default (the typical "*.exe has encountered a problem and needs to close" message)
                              12        SetUnhandledExceptionFilter CODEPTR (TraceExceptionHandler) '<--- Use this exception handler if wanting to make a better crash-proof program
                              '
                              '
                              '
                              101       LOCAL LastError AS LONG
                              '102       LOCAL WhatToTrace AS STRING
                              '103       LOCAL ErrFunc AS LONG
                              '104       LOCAL DebugTraceRunning AS LONG
                              '105       LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH
                              '106       LOCAL OverRideError AS LONG
                              107       ERR = PbErrorValue                                          'PB Clears ERR at the end of functions so to preserve it I reset it
                              108       SELECT CASE ERR                                             'Is it a PB Error?
                              109            CASE 0                                                 'Not a PB Error
                              110                 FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %NULL, LastErrorValue, %NULL, ErrorBuff, SIZEOF(ErrorBuff), BYVAL %NULL     'Format the message
                              111                 WhatToTrace = WhatToTrace + SPACE$(5) + "Unhandled WindowsError - " + STR$(LastErrorValue) + " - " + ErrorBuff + $CRLF
                              112                 WhatToTrace = WhatToTrace + SPACE$(10) + " Function = " + FunctionName + $CRLF
                              113                 WhatToTrace = WhatToTrace + SPACE$(10) + " at line: " + STR$(ErrorLineNumber) + $CRLF
                                                  #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
                              114                      WhatToTrace = WhatToTrace + SPACE$(10)+ " Last Executed: " + ErrorLineString
                                                  #ENDIF
                              115            CASE ELSE                                              'PB Error
                              116                 LastError = ERR
                              117                 WhatToTrace = WhatToTrace + SPACE$(5) + "Unhandled PbError # " + STR$(ERR) + " - " + ERROR$ + $CRLF
                              118                 WhatToTrace = WhatToTrace + SPACE$(10) + " Function = " + FunctionName + $CRLF
                              119                 WhatToTrace = WhatToTrace + SPACE$(10) + " at line: " + STR$(ErrorLineNumber)  + $CRLF
                                                  #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
                              120                      WhatToTrace = WhatToTrace + SPACE$(10)+ " Last Executed: " + ErrorLineString
                                                  #ENDIF
                              121       END SELECT
                              '122       TraceOn                                                     'If debugging then trace
                              122       TRACE ON                                                     'If debugging then trace
                              123       TracePrint WhatToTrace                               'If debugging then trace what?
                              '*** Use one of the following to decide whether to continue or not
                              '***      SetGetOverRideError(%NORESUME, OverRideError, %TRUE)        'Do not resume
                              '***      SetGetOverRideError(%RESUME, OverRideError, %TRUE)          'Resume at same line that caused the error
                              '***      SetGetOverRideError(%RESUMENEXT, OverRideError, %TRUE)      'Resume at line after the error
                              124       SELECT CASE LastError
                              125            CASE 0, %ERR_NOERROR                         'No Error
                              126                 SetGetOverRideError(%RESUMENEXT, OverRideError, %TRUE)
                              127            CASE 5, %ERR_ILLEGALFUNCTIONCALL             'Illegal function call
                              128                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              129            CASE 6, %ERR_OVERFLOW                        'Overflow                '<---This error is not currently supported.
                              130                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              131            CASE 7, %ERR_OUTOFMEMORY                     'Out of Memory
                              132                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              133            CASE 9, %ERR_SUBSCRIPTPOINTEROUTOFRANGE      'Subscript / Pointer out of range
                              134                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              135            CASE 11, %ERR_DIVISIONBYZERO                 'Division by zero         '<---This error is not currently supported.
                              136                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              137            CASE 24, %ERR_DEVICETIMEOUT                  'Device TimeOut for UDP or TCP communications
                              138                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              139            CASE 51, %ERR_INTERNALERROR                  'Internal Error
                              140                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              141            CASE 52, %ERR_BADFILENAMEORNUMBER            'Bad File Name or Number '<--- Also used for Serial Port Errors
                              142                 SetGetOverRideError(%RESUMENEXT, OverRideError, %TRUE)
                              143            CASE 53, %ERR_FILENOTFOUND                   'File not found
                              144                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              145            CASE 54, %ERR_BADFILEMODE                    'Bad File Mode
                              146                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              147            CASE 55, %ERR_FILEISOPEN                     'File is already open    '<--- Also used for Serial Port Errors
                              148                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              149            CASE 57, %ERR_DEVICEIOERROR                  'Device I/O Error        'Serial Port, TCP, UDP
                              150                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              151            CASE 58, %ERR_FILEALREADYEXISTS              'File already exists
                              152                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              153            CASE 61, %ERR_DISKFULL                       'Disk full
                              154                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              155            CASE 62, %ERR_INPUTPASTEND                   'Input past end
                              156                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              157            CASE 63, %ERR_BADRECORDNUMBER                'Bad record number
                              158                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              159            CASE 64, %ERR_BADFILENAME                    'Bad file name
                              160                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              161            CASE 67, %ERR_TOOMANYFILES                   'Too many files
                              162                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              163            CASE 68, %ERR_DEVICEUNAVAILABLE              'Device unavailable
                              164                 SetGetOverRideError(%RESUMENEXT, OverRideError, %TRUE)
                              165            CASE 69, %ERR_COMMERROR                      'COMM Error         '<---Serial Port Error
                              166                 SetGetOverRideError(%RESUMENEXT, OverRideError, %TRUE)
                              167            CASE 70, %ERR_PERMISSIONDENIED               'Permission Denied
                              168                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              169            CASE 71, %ERR_DISKNOTREADY                   'Disk not ready
                              170                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              171            CASE 72, %ERR_DISKMEDIAERROR                 'Disk media error
                              172                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              173            CASE 74, %ERR_RENAMEACROSSDISKS              'Rename across disks
                              174                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              175            CASE 75, %ERR_PATHFILEACCESSERROR            'Path/File access error
                              176                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              177            CASE 76, %ERR_PATHNOTFOUND                   'Path not found
                              178                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              179            CASE 99, %ERR_OBJECTERROR                    'Object error
                              180                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              181            CASE 241, %ERR_GLOBALMEMORYCORRUPT           'Global Memory Corrupt
                              182                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              183            CASE 242, %ERR_STRINGSPACECORRUPT            'String space corrupt
                              184                 SetGetOverRideError(%NORESUME, OverRideError, %TRUE)
                              185            CASE ELSE                                    'Either a 'Compile-Time' error (handled by PB) or Unknown what to do so just exit the function
                              186       END SELECT
                              '
                              '
                              '
                                        EXIT FUNCTION
                              20   ErrHandler:
                              21        ErrFunc = GetLastError                                      'Get API Last Error
                                        #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL, ERL$
                                        #ELSEIF (%PB_REVISION) < &H900
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL
                                        #ENDIF
                              23        SetUnhandledExceptionFilter %NULL
                              '*** Mis-Reading documentation I thought I could Resume/ResumeNext, but this is not how it works
                              '***      So non of the below attempts work
                              24        SetGetOverRideError(%UNKNOWN_VALUE, OverRideError, %UNKNOWN_VALUE)
                              25        SELECT CASE OverRideError
                              26             CASE %RESUME, 0
                              27                  SetLastError(0)
                              28                  ERRCLEAR
                              29                  RESUME
                              30             CASE %RESUMENEXT, 1
                              31                  SetLastError(0)
                              '32                  ERRCLEAR
                              '32                  ERR = 0
                              33                  RESUME NEXT
                              34             CASE %NORESUME, -1
                              35        END SELECT
                                   END FUNCTION
                              '*** Print to trace file if debugging
                                   FUNCTION TracePrint(WhatToPrint AS STRING) AS LONG
                              '101       TraceVariables                                                   'Add To whatever function you want to debug (In this case most top-level possible)
                              1         ON ERROR GOTO ErrHandler                                    'Avoid using error numbers higher than 240, as they are reserved for use in critical error situations which can never be trapped with ON ERROR.
                              2         LOCAL DebugTraceRunning AS LONG                             'Variable for if debugging
                              3         LOCAL LastErrorValue AS LONG                                'Variable for GetLastError
                              4         LOCAL PbErrorValue AS LONG                                  'Variable for PB ERR
                              5         LOCAL ErrorLineNumber AS LONG                               'Variable for line number where the error occured (or the last checked line)
                              6         LOCAL ErrFunc AS LONG                                       'Variable for if there was an error in the function
                              7         LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH                       'Variable for Win32Api Error Description
                              8         LOCAL WhatToTrace AS STRING                                 'Variable for what to log for an error
                              9         LOCAL OverRideError AS LONG                                 'Variable for if to continue even if there is an error
                              10        SetLastError(0)                                             'Ensure the last Windows error is cleared
                              11        ERRCLEAR                                                    'Ensure the last PB error is cleared
                              '          SetUnhandledExceptionFilter %EXCEPTION_EXECUTE_HANDLER      '<--- Use this exception handler if wanting to use windows default (the typical "*.exe has encountered a problem and needs to close" message)
                              12        SetUnhandledExceptionFilter CODEPTR (TraceExceptionHandler) '<--- Use this exception handler if wanting to make a better crash-proof program
                              '
                              '
                              '
                              102       ErrFunc = SetGetDebugTraceRunning(%UNKNOWN_VALUE, DebugTraceRunning, %UNKNOWN_VALUE)      'Check if Debugging
                              103       SELECT CASE DebugTraceRunning
                              104            CASE 0                                                 'Not running a trace
                              105                 FUNCTION = DebugTraceRunning
                              106            CASE ELSE
                              107                  TRACE ON
                              108                 TRACE PRINT WhatToPrint                    '<--- Chose string since I do not know what is to be printed  for log file
                              109                 FUNCTION = %FALSE
                              110       END SELECT
                              '111       TraceUnHandledFunction                                              'Macro for Local Variables and Unhandled Errors
                              '
                              '
                              '
                                        EXIT FUNCTION
                              20   ErrHandler:
                              21        ErrFunc = GetLastError                                      'Get API Last Error
                                        #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL, ERL$
                                        #ELSEIF (%PB_REVISION) < &H900
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL
                                        #ENDIF
                              23        SetUnhandledExceptionFilter %NULL
                              '*** Mis-Reading documentation I thought I could Resume/ResumeNext, but this is not how it works
                              '***      So non of the below attempts work
                              24        SetGetOverRideError(%UNKNOWN_VALUE, OverRideError, %UNKNOWN_VALUE)
                              25        SELECT CASE OverRideError
                              26             CASE %RESUME, 0
                              27                  SetLastError(0)
                              28                  ERRCLEAR
                              29                  RESUME
                              30             CASE %RESUMENEXT, 1
                              31                  SetLastError(0)
                              '32                  ERRCLEAR
                              '32                  ERR = 0
                              33                  RESUME NEXT
                              34             CASE %NORESUME, -1
                              35        END SELECT
                                   END FUNCTION
                              '--------------------------------------------------------------------------------
                              '*** Now for the DOOZYYYYyyyy....Handling GPF's and other major fatal errors
                              '*** Commented fields are ones that I have no value for (yet) but MSDN say they exist
                              '--------------------------------------------------------------------------------
                                   FUNCTION TraceExceptionHandler(BYREF lpEP AS EXCEPTION_POINTERS) AS LONG
                              '101       TraceVariables                                                   'Add To whatever function you want to debug (In this case most top-level possible)
                              1         ON ERROR GOTO ErrHandler                                    'Avoid using error numbers higher than 240, as they are reserved for use in critical error situations which can never be trapped with ON ERROR.
                              2         LOCAL DebugTraceRunning AS LONG                             'Variable for if debugging
                              3         LOCAL LastErrorValue AS LONG                                'Variable for GetLastError
                              4         LOCAL PbErrorValue AS LONG                                  'Variable for PB ERR
                              5         LOCAL ErrorLineNumber AS LONG                               'Variable for line number where the error occured (or the last checked line)
                              6         LOCAL ErrFunc AS LONG                                       'Variable for if there was an error in the function
                              7         LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH                       'Variable for Win32Api Error Description
                              8         LOCAL WhatToTrace AS STRING                                 'Variable for what to log for an error
                              9         LOCAL OverRideError AS LONG                                 'Variable for if to continue even if there is an error
                              10        SetLastError(0)                                             'Ensure the last Windows error is cleared
                              11        ERRCLEAR                                                    'Ensure the last PB error is cleared
                              '          SetUnhandledExceptionFilter %EXCEPTION_EXECUTE_HANDLER      '<--- Use this exception handler if wanting to use windows default (the typical "*.exe has encountered a problem and needs to close" message)
                              12        SetUnhandledExceptionFilter CODEPTR (TraceExceptionHandler) '<--- Use this exception handler if wanting to make a better crash-proof program
                              '
                              '
                              '
                              101       STATIC TerminateInProcess AS LONG
                              102       LOCAL ErrorRecord AS EXCEPTION_RECORD POINTER
                              103       LOCAL ErrorCode AS LONG POINTER
                              '104       LOCAL WhatToTrace AS STRING
                              105       LOCAL i AS LONG                                                  'For homing in on where the exception occurred
                              106       LOCAL CallStackFunctions AS STRING                               'For homing in on where the exception occurred
                              'MSGBOX FUNCNAME$ + $CR + "Event Fired" + $CR + STR$(TerminateInProcess) + str$(@ErrorRecord.ExceptionCode)
                              107       SELECT CASE TerminateInProcess                              'If Unloading due to error let the OS handle it.
                              108            CASE %TRUE
                              109                 SetUnhandledExceptionFilter %EXCEPTION_EXECUTE_HANDLER 'Reactivate default Error Handler
                              110                 RaiseException %NULL, %NULL, %NULL, %NULL              'Force normal Error Handler
                              '*** Exit the thread (and application if this is the only thread)
                              111                 ExitThread 0
                              112            CASE %FALSE
                              113                 TerminateInProcess = %TRUE
                              114                 ErrorRecord = lpEP.pExceptionRecord                    'Detect the actual exception record
                              115                 DO UNTIL @ErrorRecord.pExceptionRecord = 0             'Gather the exception record(s)
                              116                      CALL MoveMemory(@ErrorRecord, @ErrorRecord.pExceptionRecord, SIZEOF(ErrorRecord))
                              117                 LOOP
                              118                 ErrorCode   = @ErrorRecord.ExceptionCode
                              '*** Now we have in ErrorCode the ExceptionCode, that raised the crash, log the info
                              119                 SELECT CASE ErrorCode
                              120                      CASE %EXCEPTION_ACCESS_VIOLATION
                              121                           WhatToTrace =   "ACCESS VIOLATION" + " <---> " + "The thread tried to read from or write to a virtual address for which it does not have the appropriate access"
                              122                      CASE %EXCEPTION_ARRAY_BOUNDS_EXCEEDED
                              123                           WhatToTrace =   "ARRAY BOUNDS EXCEEDED" + " <---> " + "The thread tried to access an array element that is out of bounds and the underlying hardware supports bounds checking."
                              124                      CASE %EXCEPTION_BREAKPOINT
                              125                           WhatToTrace = "BREAKPOINT" + " <---> " + "A breakpoint was encountered."
                              126                      CASE %EXCEPTION_DATATYPE_MISALIGNMENT
                              127                           WhatToTrace =   "DATATYPE MISALIGNMENT" + " <---> " + "The thread tried to read or write data that is misaligned on hardware that does not provide alignment. For example, 16-bit values must be aligned on 2-byte boundaries"
                              128                      CASE %EXCEPTION_FLT_DENORMAL_OPERAND
                              129                           WhatToTrace =  "FLOAT DENORMAL OPERAND" + " <---> " + "One of the operands in a floating-point operation is denormal. A denormal value is one that is too small to represent as a standard floating-point value."
                              130                      CASE %EXCEPTION_FLT_DIVIDE_BY_ZERO
                              131                           WhatToTrace =  "FLOAT DIVISION BY ZERO" + " <---> " + "The thread tried to divide a floating-point value by a floating-point divisor of zero."
                              132                      CASE %EXCEPTION_FLT_INEXACT_RESULT
                              133                           WhatToTrace =  "FLOAT INEXACT RESULT" + " <---> " + "The result of a floating-point operation cannot be represented exactly as a decimal fraction."
                              134                      CASE %EXCEPTION_FLT_INVALID_OPERATION
                              135                           WhatToTrace =  "FLOAT INVALID OPERATION" + " <---> " + "This exception represents any floating-point exception not included in this list."
                              136                      CASE %EXCEPTION_FLT_OVERFLOW
                              137                           WhatToTrace =  "FLOAT OVERFLOW" + " <---> " + "The exponent of a floating-point operation is greater than the magnitude allowed by the corresponding type."
                              138                      CASE %EXCEPTION_FLT_STACK_CHECK
                              139                           WhatToTrace =  "FLOAT STACK CHECK" + " <---> " + "The stack overflowed or underflowed as the result of a floating-point operation."
                              140                      CASE %EXCEPTION_FLT_UNDERFLOW
                              141                           WhatToTrace =  "FLOAT UNDERFLOW" + " <---> " + "The exponent of a floating-point operation is less than the magnitude allowed by the corresponding type."
                              142                      CASE %EXCEPTION_ILLEGAL_INSTRUCTION
                              143                           WhatToTrace =  "ILLEGAL INSTRUCTION" + " <---> " + "The thread tried to execute an invalid instruction."
                              144                      CASE %EXCEPTION_IN_PAGE_ERROR
                              145                           WhatToTrace = "IN PAGE ERROR" + " <---> "
                              146                           WhatToTrace = WhatToTrace + "The thread tried to access a page that was not present, and the system was unable to load the page."
                              147                           WhatToTrace = WhatToTrace + "For example, this exception might occur if a network connection is lost while running a program over "
                              148                           WhatToTrace = WhatToTrace + "the network."
                              149                      CASE %EXCEPTION_INT_DIVIDE_BY_ZERO
                              151                           WhatToTrace =   "INTEGER DIVISION BY ZERO" + " <---> " + "The thread tried to divide an integer value by an integer divisor of zero."
                              152                      CASE %EXCEPTION_INT_OVERFLOW
                              153                           WhatToTrace =   "INTEGER OVERFLOW" + " <---> " + "The result of an integer operation caused a carry out of the most significant bit of the result."
                              '154                      CASE %EXCEPTION_INVALID_DISPOSITION
                              '155                           WhatToTrace =   "INVALID DISPOSITION" + " <---> " + "An exception handler returned an invalid disposition to the exception dispatcher. Programmers using a high-level language such as C should never encounter this exception."
                              '156                      CASE %EXCEPTION_NONCONTINUABLE_EXCEPTION
                              '157                           WhatToTrace =   "NONCONTINUABLE EXCEPTION" + " <---> " + "The thread tried to continue execution after a noncontinuable exception occurred."
                              158                      CASE %EXCEPTION_PRIV_INSTRUCTION
                              159                           WhatToTrace =   "PRIVATE INSTRUCTION" + " <---> " + "The thread tried to execute an instruction whose operation is not allowed in the current machine mode."
                              160                      CASE %EXCEPTION_SINGLE_STEP
                              161                           WhatToTrace =   "SINGLE STEP" + " <---> " + "A trace trap or other single-instruction mechanism signaled that one instruction has been executed."
                              162                      CASE %EXCEPTION_STACK_OVERFLOW
                              163                           WhatToTrace =  "STACK OVERFLOW" + " <---> " + "The thread used up its stack."
                              164                      CASE ELSE
                              165                           WhatToTrace =  CHR$(0)
                              166                 END SELECT
                              167                 FOR i = CALLSTKCOUNT TO 1 STEP -1
                              168                      CallStackFunctions = CallStackFunctions + SPACE$(10) + CALLSTK$(i) + $CRLF
                              169                 NEXT i
                              '*** Code for writing a crash-log, save opened documents etc...
                              170                 WhatToTrace = SPACE$(5) + "Unhandled WindowsException - " + STR$(@ErrorRecord.ExceptionCode) + " - " + WhatToTrace  + $CRLF + SPACE$(5) + " Function = " + CallStackFunctions + " at line: " + STR$(ERL)
                              171                 TracePrint WhatToTrace
                              '*** Exit the thread (and application if this is the only thread)
                              172                 ExitThread 0                  'This will stop the typical "*.exe has encountered a problem and needs to close" error message to send a report to M$
                              173       END SELECT
                              '
                              '
                              '
                                        EXIT FUNCTION
                              20   ErrHandler:
                              21        ErrFunc = GetLastError                                      'Get API Last Error
                                        #IF (%PB_REVISION) > = &H900                                          '<--- If Compiler version is 9 or higher then its able to handle classes
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL, ERL$
                                        #ELSEIF (%PB_REVISION) < &H900
                              22             TraceLastError FUNCNAME$, ErrFunc, ERR, ERL
                                        #ENDIF
                              23        SetUnhandledExceptionFilter %NULL
                              '*** Mis-Reading documentation I thought I could Resume/ResumeNext, but this is not how it works
                              '***      So non of the below attempts work
                              24        SetGetOverRideError(%UNKNOWN_VALUE, OverRideError, %UNKNOWN_VALUE)
                              25        SELECT CASE OverRideError
                              26             CASE %RESUME, 0
                              27                  SetLastError(0)
                              28                  ERRCLEAR
                              29                  RESUME
                              30             CASE %RESUMENEXT, 1
                              31                  SetLastError(0)
                              '32                  ERRCLEAR
                              '32                  ERR = 0
                              33                  RESUME NEXT
                              34             CASE %NORESUME, -1
                              35        END SELECT
                                   END FUNCTION
                              #ENDIF
                              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? "

                              Comment


                              • #16
                                Gosta,
                                I gotta ask from the
                                ?"here",,FuncName$
                                To me it looks like a PBCC thing? Can PBCC create Dialogs/Windows?
                                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? "

                                Comment


                                • #17
                                  Originally posted by Cliff Nichols View Post
                                  Gosta,
                                  I gotta ask from the

                                  To me it looks like a PBCC thing? Can PBCC create Dialogs/Windows?
                                  ?"here",,FuncName$

                                  is merely a shorcut for MsgBox "here",,FuncName$

                                  Dunno if PBCC can creat Dialogs/Windows. I don't use it.

                                  ===============================
                                  "Intellectuals solve problems;
                                  geniuses prevent them."
                                  Albert Einstein
                                  ===============================
                                  Last edited by Gösta H. Lovgren-2; 4 Nov 2008, 08:50 PM.
                                  It's a pretty day. I hope you enjoy it.

                                  Gösta

                                  JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                                  LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                                  Comment


                                  • #18
                                    PB/CC help:
                                    A question mark may be used as an abbreviation for the PRINT statement.
                                    PB/Win Help:
                                    Syntax MSGBOX txt$ [, [style%], title$]

                                    ? txt$ [, [style%], title$]
                                    Recent demo which "compiles and runs 'as is' with either compiler" using same: Generic 'ADO' Connection and Query Tester (CC 5+/Win 9+) 11-02-08
                                    Last edited by Michael Mattias; 5 Nov 2008, 08:25 AM.
                                    Michael Mattias
                                    Tal Systems (retired)
                                    Port Washington WI USA
                                    [email protected]
                                    http://www.talsystems.com

                                    Comment


                                    • #19
                                      I forgot about the MsgBox shortcut.

                                      But now that is past, I gotta wonder why Gosta's version shows nothing???

                                      I'm confused, Cliff. Just what exactly is your code supposed to do? I loaded and ran it, but nothing happens. I mean it compiles okay (at least no errors show) but that's it. No Dialogs, no windows, ...

                                      I can even get it to show a MsgBox
                                      I added your line of code just to see and still shows messagebox here.

                                      Anyone else get the same problem? (curious if I tripped off some Antivirus or malware program that makes it not show?

                                      Gosta, if watching the processes window does the program show it is running?
                                      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? "

                                      Comment


                                      • #20
                                        Originally posted by Cliff Nichols View Post
                                        I forgot about the MsgBox shortcut.

                                        But now that is past, I gotta wonder why Gosta's version shows nothing???

                                        I added your line of code just to see and still shows messagebox here.

                                        Anyone else get the same problem? (curious if I tripped off some Antivirus or malware program that makes it not show?

                                        Gosta, if watching the processes window does the program show it is running?
                                        Cliff, when I ACD the Task Mgr the program is not running. Have looked every time (almost). And JF Pro won't run multiple instances from the IDE (if set that way). Gives a "Destination File" error. Am (very) familar with it. Do it all the time and often have to ACD to close what I'm working on.

                                        I doubt it is a virus checker. Use Trend Micro PC-Cillin and it hasn't interfered with anything before. Besides it always warns when it finds a bummer.

                                        It's possible it's just my system but I have no idea how to check. And lacking confirmation that the program runs in other similar environments (ie XP Pro), am not inclined to start looking. Just chalk it up to a "feature".

                                        ===================================================
                                        "Dogma is the sacrifice of wisdom to consistency."
                                        Lewis Perelman
                                        ===================================================
                                        It's a pretty day. I hope you enjoy it.

                                        Gösta

                                        JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                                        LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                                        Comment

                                        Working...
                                        X