March 27, 1999

Regular Expressions in JavaScript 1.2

One of the most powerful new features of JavaScript 1.2 is a set of objects and methods to provide regular expression functionality. Perl programmers have relied on regular expressions for years to do pattern matching and pattern manipulation, and now that power is available in any browser that supports JavaScript

Propagate User Exceptions

In Java, you can propagate checked exceptions up a class hierarchy in two ways. First, you can declare the exception in the “throws” clause of the enclosing method. Second, you can catch the exception in a try-catch block and rethrow it. You can use the second mechanism when your program

Destructors Should Handle Exceptions Locally

It is legal to call a function that may throw an exception inside a destructor. However, it is important to handle any exception that might be thrown from such a function inside the destructor body. void cleanup() throw (int);class C {public: ~C();};C::~C() { try { cleanup(); } catch(int) { //handle

Avoid Improper Inheritance

Using public inheritance with two classes that do not fully comply with the is-a relation (although they are related to one another) is a common design mistake. For example, deriving class Stack from class List may indicate a design flaw. A stack is not a list. Both classes support some

Beware of Using setjmp and longjmp

Using a longjmp() in C++ is dangerous because it jumps out of a function, without unwinding the stack first. Consequently, destructors of local objects are not invoked. As a rule, long jumps should be used in pure C exclusively. In C++ code, you should use standard exception handling instead.

Is the Array Dimensioned?

Use this function to determine whether a dynamic array has been dimensioned. I use dynamic arrays to store small, foreign key tables locally for fast lookups. Not wanting to load all the arrays initially, I load them only when needed and only once. I wanted to exploit the fact that

Quick Check on Collection Key

You might need to determine whether a certain key is in a collection. The Collection object doesn’t provide a method to retrieve a key after you add an object to the collection. Instead of keeping a separate list of the keys in the collection, use this function: Public Function IsKeyInCollection(col

Set the Width of a ListView Column

The ListView Windows control has some additional features that haven’t been exposed in the OCX provided with VB. One feature can shrink or enlarge columns automatically to ensure that data in each column is visible and that no screen space is wasted. Use this function to make an API call:

Keep Track of Global Variables

Forgetting the names of global variables is easy to do. You can solve this problem by letting VB remember the variables for you by making the variables into fields of a type definition: Private Type GlobalVarsINIFilePath As String SqlServerConnection As rdoConnection UserName As String Password As String DSN As StringEnd

No more posts to show