Announcement

Collapse
No announcement yet.

Err is local

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

  • Lance Edmonds
    replied
    I don't think that ERR and ERRAPI could ever be made GLOBAL because it opens up too meny problems for threaded and reenterant sub/function calls...

    The usual technique is to use the same technique as the Windows API offers - instead of using SUB's, use a function that returns an error code. You could also call a function that could be used to store the ERR and ERRAPI values in static variables, and then these could be retrieved from other subs/functions.

    Code:
    ' Psuedocode
    FUNCTION GlobalError(BYVAL PBerr&) AS LONG
      STATIC LastErr&
      IF PBErr& = 0 THEN 
        FUNCTION = LastErr&
      ELSE
        LastErr& = PBerr&
      END IF
    END FUNCTION
      
    ...
    call GlobalError(7) ' set "lasterr" to 7
    ...
    if GlobalError(0) = 7 THEN...  ' Retrieve the last error
    ...
    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Terry Webb
    replied
    Here's what I do:

    Code:
    SUB                                         _
    Show_Error                                  _
    (                                           _
        BYVAL   proc            AS  STRING      _   '   procedure
    ,   BYVAL   m               AS  STRING      _   '   message
    ,   BYVAL   e               AS  LONG        _   '   ERR
    ,   BYVAL   ea              AS  LONG        _   '   ERRAPI
    )
    
    #REGISTER   NONE
    
    LOCAL   s                       AS  STRING
    
    '   procedure
    s   =   "Procedure: "                       _
        +   proc                                _
        +   $CRLF                               _
        +   $CRLF
    
    '   messsage
    IF  LEN(m)                                  THEN
    s   =   s                                   _
        +   m                                   _
        +   $CRLF                               _
        +   $CRLF
    END IF
    
    '   ERR
    s   =   s                                   _
        +   "Error # "
    SELECT  CASE    e
        CASE    0
            s   =   s                           _
                +   " 0 No error"
        CASE    5
            s   =   s                           _
                +   " 5 Illegal function call"
        CASE    7
            s   =   s                           _
                +   " 7 Out of memory"
        CASE    9
            s   =   s                           _
                +   " 9 Subscript / Pointer out of range"
        CASE    24
            s   =   s                           _
                +   " 24 Device Time-Out"
        CASE    51
            s   =   s                           _
                +   " 51 Internal error"
        CASE    52
            s   =   s                           _
                +   " 52 Bad file name or number"
        CASE    53
            s   =   s                           _
                +   " 53 File not found"
        CASE    54
            s   =   s                           _
                +   " 54 Bad file mode"
        CASE    55
            s   =   s                           _
                +   " 55 File is already open"
        CASE    57
            s   =   s                           _
                +   " 57 Device I/O error"
        CASE    58
            s   =   s                           _
                +   " 58 File already exists"
        CASE    61
            s   =   s                           _
                +   " 61 Disk full"
        CASE    62
            s   =   s                           _
                +   " 62 Input past end"
        CASE    63
            s   =   s                           _
                +   " 63 Bad record number"
        CASE    64
            s   =   s                           _
                +   " 64 Bad file name"
        CASE    67
            s   =   s                           _
                +   " 67 Too many files"
        CASE    68
            s   =   s                           _
                +   " 68 Device unavailable"
        CASE    70
            s   =   s                           _
                +   " 70 Permission denied"
        CASE    71
            s   =   s                           _
                +   " 71 Disk not ready"
        CASE    72
            s   =   s                           _
                +   " 72 Disk media error"
        CASE    74
            s   =   s                           _
                +   " 74 Rename across disks"
        CASE    75
            s   =   s                           _
                +   " 75 Path/file access error"
        CASE    76
            s   =   s                           _
                +   " 76 Path not found"
        CASE    ELSE
            s   =   s                           _
                +   FORMAT$(e)
    END SELECT
    s   =   s                                   _
        +   $CRLF                               _
        +   $CRLF
    
    '   ERRAPI
    IF  ea                                      THEN
    s   =   s                                   _
        +   "API # "                            _
        +   FORMAT$(ea)                         _
        +   $CRLF                               _
        +   $CRLF
    END IF
    
    MSGBOX                                      _
        s                                       _
    ,       %MB_OK                              _
        OR  %MB_ICONERROR                       _
    ,   "Error"
    
    END SUB
    Example code to check for error and call Show-Error.

    Code:
    '   error?
    IF  (ERR    +   ERRAPI)                     THEN
    CALL                                        _
    Show_Error                                  _
    (                                           _
        "Load_Array"                            _   '   procedure
    ,   "Error occurred during Win32API ReadFile operation."    _   '   message
    ,   ERR                                     _
    ,   ERRAPI                                  _
    )
    END IF
    HTH,
    Terry


    [This message has been edited by Terry Webb (edited June 21, 2000).]

    Leave a comment:


  • E B Knoppert
    Guest started a topic Err is local

    Err is local

    Just found out that the Err and ErrApi are kept local.
    When i have an err in a special proc. to open a file for example, i tried to read the err result in the calling proc.
    Unf. this read 0.

    Is there a mode in PB to make this one global?

    (The example above WAS just an example, normally the proc. returns the filehandle or sort of, this would conflict with a err value, tricks enough of course.)

Working...
X