Error Handling  
 

Error conditions can occur in one of two general circumstances, either when setting a property in the control or when calling a method. If the error occurs when setting a property, an exception will be generated which must be caught and handled by the application. Failure to do this will typically result in the program displaying an error message and then terminating. For example, in Visual Basic, the On Error statement can be used to establish an error handler.

Methods are a bit different in that errors can be handled in one of two ways. By default, when a method is called it will return a numeric value. A value of zero indicates that the method completed successfully and that no error occurred. A non-zero return value specifies an error code which indicates the reason for the failure. For programmers who prefer to handle exceptions, rather than check return values for each method, the controls have a property called ThrowError. If set to True, then when a method fails it will throw an exception that must be caught by the application. Just as an error that occurs when setting a property, if the ThrowError property is set to true and an error occurs without there being an exception handler in place, the application will typically terminate.

To determine the error code for the last error generated by the control, use the LastError property. To display a description of the error to the user, the LastErrorString property will can be used. This returns a string that describes the error which corresponds to the value of the LastError property. It is permitted to set the LastError property to a value of zero in order to clear the last error code.