Error Trapping

Prayder

Registered User.
Local time
Today, 10:09
Joined
Mar 20, 2013
Messages
303
What is the purpose of error trapping?
 
so you dont see the ugly default access errors and can "take care" of a gentle fix?
 
At its most basic level, it lets you provide error messages when errors are encountered without causing the program to crash and giving the user access to the code. It is also often used, as namliam pointed out, to handle expected errors rather than just bringing the program to a halt.
 
The goal of well designed error handling code is to anticipate potential errors, and correct them at run time or to terminate code execution in a controlled, graceful method. Your goal should be to prevent unhandled errors from arising.
 
So is there like a default template of error trapping code that would be used for any vba module?
 
procedure, not module - and actually, process within a procedure -indeed any process that may go wrong

let's say you want to open a disk file, and you execute a command called, lets say

"open file"

so you could get many errors

- the folder may not exist
- the file may not exist
- the file may already be in use
- the folder may be access-protected against you
- the file may be access-protected against you
- the channel you specify may already be in use
- your command may be written incorrectly

-probably loads more

all of these will generate run time errors that you can handle and inform your users what the problem is without either a) the programming just halting, as in a .de version, or b) the programme taking them to the debug window
 

Users who are viewing this thread

Back
Top Bottom