Error handler (1 Viewer)

falcondeer

Registered User.
Local time
Today, 13:07
Joined
May 12, 2013
Messages
101
Hi everybody

I am about to distribute the front end of my split DB to users, isn't a good idea to put an error handler in the DB before that, and how could I do that.

Is there a not complicated one to put in my DB so it will not crash.

Thanks.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 21:07
Joined
Sep 12, 2006
Messages
15,640
It's not one error handler.

Every time you write code that might go wrong, your dbs needs to pick up the error. but more importantly deal with it.
It's not enough to just know that there is an error. Some errors don't matter (but still need to be intercepted, and handled). Others are much more important. So possibly every individual sub or function needs a error handler. It's not quite as bad as that, but some development tools will automatically insert an error handler framework in every sub or function.

For instance, every time you divide two numbers you ought to have an error handler in case the divisor is zero.
Arithmetical operations might give you an overflow error. You need to manage this. You might need to change a data type in your dbs, or you might just report that a number is too big, and then either carry on, or cancel the process.
A file or folder you expect to be in the system may not be there, or may already be there. Virtually every time you have any interaction with files (i/o) you need an error handler.

for example, the only way you can test whether a certain field exists in a table is to test for it. If the test fails, you get an error which you need to handle and then continue appropriately.

Do you ever get situations where your code errors, informs you of a problem, and jumps into the code? That's an unhandled error, and you don't want users to ever see code. In fact, you may want to distribute a .accde verson of the database, so they just cannot change your dbs design. If you do that and there is an error, you will be getting phone calls just saying "my database isn't working", as the dbs reacts slightly differently in an .accde.

The error messages you get in access just give you text. They don't give you an error number. Sometimes the error number is really helpful, so you often add your own error handler to present the error in a different way, and it becomes a helpful designed message rather than a standard and less helpful access message.

Some "errors" aren't even errors, but do affect your programme. If you try to insert a new record, but it's already there, it's not a programming error, and it's not directly trappable. It's called a form error, and you can add form error handlers to manage these types of errors.

A lot of code is defensive. Error handlers, input validation, input sense-checking, ensuring some fields can't be blank/null and so on. So it's more than error handling - it's everything to make the dbs robust.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:07
Joined
Feb 28, 2001
Messages
27,146
I'm with Dave 100% on this one. Simple functions need error handlers so that they will return something, even if it is an empty string or a zero. Subroutines need to "clean up" after themselves so that you don't end up with "dangling" structures that were opened based on a global or ByRef object but then not closed properly when done. It is imperative that you look at each entry point. Sometimes it will be clear that NOTHING can go wrong. However, if a function has division, exponentiation, or the potential for large numbers, then even "simple" math can fail.

The ultimate issue is that if you take an error and have not protected yourself against it, your app will hit the debugger. Depending on how you distributed the app, the end user might be presented with an impossibility - how to gracefully exit from that problem without losing data.
 

Cronk

Registered User.
Local time
Tomorrow, 06:07
Joined
Jul 4, 2013
Messages
2,771
Going a step further, I recommend that the error handler also save a copy of the error and the procedure in which it occurred as well as the user and timestamp. That way you can monitor for reoccurring issues and fix them. I've found it also helps when a user gives a very vague advice such as Ï get error warnings when I use the database"
 

falcondeer

Registered User.
Local time
Today, 13:07
Joined
May 12, 2013
Messages
101
It's not one error handler.

Every time you write code that might go wrong, your dbs needs to pick up the error. but more importantly deal with it.
It's not enough to just know that there is an error. Some errors don't matter (but still need to be intercepted, and handled). Others are much more important. So possibly every individual sub or function needs a error handler. It's not quite as bad as that, but some development tools will automatically insert an error handler framework in every sub or function.

For instance, every time you divide two numbers you ought to have an error handler in case the divisor is zero.
Arithmetical operations might give you an overflow error. You need to manage this. You might need to change a data type in your dbs, or you might just report that a number is too big, and then either carry on, or cancel the process.
A file or folder you expect to be in the system may not be there, or may already be there. Virtually every time you have any interaction with files (i/o) you need an error handler.

for example, the only way you can test whether a certain field exists in a table is to test for it. If the test fails, you get an error which you need to handle and then continue appropriately.

Do you ever get situations where your code errors, informs you of a problem, and jumps into the code? That's an unhandled error, and you don't want users to ever see code. In fact, you may want to distribute a .accde verson of the database, so they just cannot change your dbs design. If you do that and there is an error, you will be getting phone calls just saying "my database isn't working", as the dbs reacts slightly differently in an .accde.

The error messages you get in access just give you text. They don't give you an error number. Sometimes the error number is really helpful, so you often add your own error handler to present the error in a different way, and it becomes a helpful designed message rather than a standard and less helpful access message.

Some "errors" aren't even errors, but do affect your programme. If you try to insert a new record, but it's already there, it's not a programming error, and it's not directly trappable. It's called a form error, and you can add form error handlers to manage these types of errors.

A lot of code is defensive. Error handlers, input validation, input sense-checking, ensuring some fields can't be blank/null and so on. So it's more than error handling - it's everything to make the dbs robust.
Thank you a lot.
 

falcondeer

Registered User.
Local time
Today, 13:07
Joined
May 12, 2013
Messages
101
I'm with Dave 100% on this one. Simple functions need error handlers so that they will return something, even if it is an empty string or a zero. Subroutines need to "clean up" after themselves so that you don't end up with "dangling" structures that were opened based on a global or ByRef object but then not closed properly when done. It is imperative that you look at each entry point. Sometimes it will be clear that NOTHING can go wrong. However, if a function has division, exponentiation, or the potential for large numbers, then even "simple" math can fail.

The ultimate issue is that if you take an error and have not protected yourself against it, your app will hit the debugger. Depending on how you distributed the app, the end user might be presented with an impossibility - how to gracefully exit from that problem without losing data.
Thank you.
 

falcondeer

Registered User.
Local time
Today, 13:07
Joined
May 12, 2013
Messages
101
Going a step further, I recommend that the error handler also save a copy of the error and the procedure in which it occurred as well as the user and timestamp. That way you can monitor for reoccurring issues and fix them. I've found it also helps when a user gives a very vague advice such as Ï get error warnings when I use the database"
Thanks.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:07
Joined
Feb 19, 2002
Messages
43,231
I start with a generic error handler for each procedure. Sometimes I know what error codes might be generated but other times I don't. So, if I know a code, I include it in the select case. Otherwise, I just wait for an error to happen and add an appropriate trap later.

Code:
ExitProc:
'   add cleanup code

    Exit Sub
ErrProc:
    Select Case Err.Number
        Case Else
            Msgbox Err.Number & "--" & Err.Description
    End Select
End Sub
Code:
ExitProc:
    Exit Sub
ErrProc:
    Select Case Err.Number
        Case 2501
            Msgbox "some message"
        Case Else
            Msgbox Err.Number & "--" & Err.Description
    End Select
    Resume ExitProc
End Sub
 

Users who are viewing this thread

Top Bottom