Results 1 to 4 of 4

Thread: error

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Posts
    77

    error

    Hi!!

    i would like to how work the OnError GoTo .....


    In my form i have to do a lot of thing in my button insert and if something happening strange when i pressed the button insert i want to catch the error.

    How dont know how to do.
    how do we do to know which number of error!!!
    thank lot
    karo dont

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Sub Command1_Click()
    2. On Error Goto ErrRtn
    3. 'code to do your thing
    4. Exit Sub
    5. ErrRtn:
    6. Msgbox Err & " " & Error
    7. End Sub

  3. #3
    DerFarm
    Guest
    Be careful with the error handlers. It is sometimes best to have
    one for each section of code, sometimes one handler for the
    entire program.

    When you have declared "on error goto dumb" that stays in force
    until the next on error statement. Thus, 25 system calls and
    1000 VB lines of code later, you'll endup at dumb if you create an
    error.

    BTW, on error goto 0 clears the last error goto statement.

    Good Luck

  4. #4
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    I like to use functions and have them return an error code and then raise the error from the originating procedure. I don't always do that if I definitely want to log the error where the error occured. The plus side to this is that I don't have to make sure only one error message is raised if the call is coming back up through several procedures. The downside is that the error isn't reported where it actually occured.

    I also log errors in a central handler unless they are validation errors (bad user input).

    VB Code:
    1. Sub A ()
    2. dim ireturn as long
    3.  
    4. on error goto errhandler
    5.  
    6. ireturn = savefile
    7. if ireturn <> 0 then err.raise ireturn
    8.  
    9. exit sub
    10.  
    11. errHandler:
    12. logerror error, err
    13.  
    14. End sub
    15.  
    16. Function SaveFile() as long
    17. dim iReturn as long
    18.  
    19. on error goto errhandler
    20.  
    21. iReturn = Validate
    22. if iReturn <> 0 then err.raise ireturn
    23.  
    24. iReturn = GetFilename
    25. if iReturn <> 0 then exit function
    26.  
    27. iReturn = WriteFile
    28. if iReturn <> 0 then  exit function
    29.  
    30. exit function
    31.  
    32. errHandler:
    33. logerror error, err
    34.  
    35. end Function
    36.  
    37. function Validate
    38.  
    39. on error goto errhandler
    40.  
    41. ' do validate stuff
    42.  
    43. exit function
    44.  
    45. errHandler:
    46. msgbox "You did dumb data input stuff."
    47.  
    48. end function
    49.  
    50. function GetFilename
    51.  
    52. on error goto errhandler
    53.  
    54. ' do stuff
    55.  
    56. exit function
    57.  
    58. errHandler:
    59. logerror
    60.  
    61. end function
    62.  
    63. and so on

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width