Article # 107, added by Geoworks, historical record
| first |
previous |
index |
next |
last |
White Paper on Writing Error-Checking code
Writing EC code into your GEOS apps =================================== I'm sure you've experienced a time when you were setting the value of variables indirectly by using a pointer to the variables. And I'm sure at some point that pointer was trashed or not dereferenced and you started writing all over memory. Well, GEOS has a routine to check for that (ECCheckBounds). Just think how much time you could save by using EC routines to catch such problems as illegal handles, corrupt chunk arrays, and bad return values. And don't think that you're going to slow down your app by using EC routines. The EC routines are only needed while you are testing your application. Once you've debugged your app and are ready to ship, just compile without the EC routines and you'll have a fast, correct application. Now that I've convinced you to use error-checking code in your GEOS apps, lets take a look at how to use EC code. The first thing you must learn to do is surround EC routine calls with the EC() macro. Using the EC() macro tells GOC to include the error-checking code in only the EC version of your app. When you compile the NC version of your app, GOC will ignore anything inside the parentheses of the EC() macro. This is good for two reasons. First, not all EC routines are found in the NC version of GEOS. Second, you don't want to slow down your shipping app with calls to EC routines once you've debugged your app. The second thing to know is that there are many EC routines in GEOS that check all kinds of things. Many check handles such as memory handles, file handles, vmem handles, lmem handles, and gstate handles. One routine you'll have to watch for is ECCheckGStateHandle. The C stub for this routine had a bug in it that caused it to always cause an ILLEGAL_HANDLE error. You can, however, call the assembly version of the routine and it will work. The error in the C stub was fixed as of 8/8/96. Thirdly, not only can you use EC routines in GEOS to find bugs, but you can also write your own error checking code that checks internal data structures and values. For instance, if a routine is called and you are expecting a parameter whose value falls within a certain range, you can check that using the EC_ERROR_IF() macro. EC_ERROR_IF lets you evaluate a boolean expression, and if it is true a fatal error will be flagged. And since this is an EC macro it will only be included in the EC version of your geode. Now that you have an idea of how to use EC routines in your GEOS application, lets review the advantages to using EC code: - Catch bugs sooner, before they cause other misleading problems. - Catch bugs you wouldn't otherwise find (ie. system doesn't check for them). - Helps produce near-perfect programs (we can dream).