Announcement

Collapse
No announcement yet.

Avoid trapping error 0

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

  • Avoid trapping error 0

    The function ShowError is a copy of part of WinErr for PB CC.
    I found by experiment that the On Error works TOO well - intermittently
    gives "Error 0 = The operation completed succesfully".
    Using "If ErrApi then BtmLneErr" does not do this.
    But neither method replaces or precedes the Window messages about
    "... illegal operation and will be shut down" which is precisely the
    object of the excercise.
    '_______________________________________________________________________
    Code:
    Function ShowError (ByVal x&) As String
     If ErrApi Then ShwErrErr
      FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, ByVal %NULL, x&, %NULL, errbfr, SizeOf(errbfr), ByVal %NULL
    
      If Len(errbfr) Then
        Function = "Error " & Format$(x&) & " = " & errbfr
      Else
        Function = "Unknown error code: " & Format$(x&)
      End If
     Exit Function
    ShwErrErr:
     MsgBox(showError(ErrApi)+" in WPtester, ShowError")
     End Function      '(ShowError)
    '_______________________________________________________________________
    
    Function BottomLine (ByVal cL&) As Long
     If ErrApi Then BtmLneErr
    ' On Error Goto BtmLneErr
     While cL&<dtlCnt& And Val(Left$(IstLst$(cL&+1),4))=Val(Left$(IstLst$(cL&),4))
      Incr cL&
      Wend              'Establish the LAST line (on screen) of the
     Function=cL&       'order item per cL& (see sub SetFirstLastList
     Exit Function      'above)
    BtmLneErr:
     MsgBox(showError(ErrApi)+" in WPtester, BottomLine")
     End Function      '(BottomLine)
    '_______________________________________________________________________


    ------------------
    Last edited by Gary Beene; 12 Jul 2014, 08:59 PM. Reason: Code: tags

  • #2
    I had the same problem once. Did some reading and realized not all API calls Set "Last Error" or provide a value to the GetLastError call (which I assum is the underlying function servicing the PB ERRAPI function).

    For calls which don't, you can use the SetLastError API to tell Windows what to look for. But unless you know which APIs the PBRT calls, in what order, this may get you precisely nowhere.

    MCM


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

    Comment


    • #3
      Thanks, Michael. In any event my code as posted would not be very
      useful since the ErrApi has to be present upon entry, and will
      definitely have arisen in a preceding sub or function.

      One could also try

      On error goto xxxErr

      and there ---

      xxxErr:
      if ErrApi=0 then resume dword abc

      --- but to maintain the dword (abc) makes it totally
      impracticable, also labeling EVERY LINE of code!!!

      Pity; the error in text form would be extremely useful to those
      who can't make sense of the register values/stack dumps etc.
      provided with the Windows ultimati.

      ------------------

      Comment

      Working...
      X