+ Reply to Thread
Results 1 to 2 of 2

Error trapping

  1. #1
    hshayh0rn
    Guest

    Error trapping

    I would like to know if there is a way to catch a specific error. I allow
    users to conditionally select files by checking boxs on a userform. If the
    file doens't exist I would like to process the program as if the box was not
    checked. The problem I'm having is not knowing which file is missing so I
    don't know what part of the program to skip. For example:

    Run-tim error '1004':

    'filesname.CSV' COULD NOT BE FOUND. CHECK THE SPELLING OF THE FILE NAME, AND
    VERIFY THAT THE FILE LOCATION IS CORRECT.

    If filename.csv is missing I would like to skip the code that processes the
    data in filename.csv. I could handle it with a bunch of error routines but I
    would rather find out if I can extract the name of the missing file from the
    error.

    Thanks in advance for the help!

  2. #2
    Mat P:son
    Guest

    RE: Error trapping

    The Dir function is a rather powerful way of trawling for files and
    directories. Maybe you could use Dir to check whether or not the file exists
    before you try to access it, and thus your code wouldn't have to throw
    exceptions at all?

    IMHO, exceptions should not be used as a mechanism to handle standard
    conditions that you can easily anticipate and address before they actually
    cause you any trouble. One typical example of such a condition is when the
    file you're trying to access is missing -- instead of trying to catch the
    error I think you should try to prevent it...

    Anyhow, if you want to handle only certain types of errors you can always
    check what's stored in the Err object (Number and Description). Then you let
    your error handler take care of the errors you want to manage, and just
    re-throw the rest.

    Cheers,
    /MP

    "hshayh0rn" wrote:

    > I would like to know if there is a way to catch a specific error. I allow
    > users to conditionally select files by checking boxs on a userform. If the
    > file doens't exist I would like to process the program as if the box was not
    > checked. The problem I'm having is not knowing which file is missing so I
    > don't know what part of the program to skip. For example:
    >
    > Run-tim error '1004':
    >
    > 'filesname.CSV' COULD NOT BE FOUND. CHECK THE SPELLING OF THE FILE NAME, AND
    > VERIFY THAT THE FILE LOCATION IS CORRECT.
    >
    > If filename.csv is missing I would like to skip the code that processes the
    > data in filename.csv. I could handle it with a bunch of error routines but I
    > would rather find out if I can extract the name of the missing file from the
    > error.
    >
    > Thanks in advance for the help!


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1