Salesforce

How Do I Handle a Database Error or Exception? (Magic xpa 4.x)

« Go Back

Information

 
Created BySalesforce Service User
Approval Process StatusPublished
Objective
Description

How Do I Handle a Database Error or Exception? (Magic xpa 4.x)

When a program causes the underlying database to generate an error, you can choose to handle that error within your program rather than using the default Magic xpa error handling. This is done by using a particular type of Event handler, where the Event Type is “Error”.

Creating an Error handler

  1. Go to the Logic tab.

  2. Press Ctrl+H to create a header line.

  3. Type E to select Event. The cursor will jump to the next field.

  4. Zoom to bring up the Event dialog.

  5. Select the Error Event type.

  6. Zoom from the Event field to select the error you want to trap.

  7. Set the Directive property to control how you want the Magic xpa engine to respond to the error. The engine directive tells the engine what to do after the error handler has been executed. Choosing “As strategy” will tell the engine to follow the error behavior strategy of the task (Ctrl+P, Data tab). Other options such as “Ignore” “Rollback & Restart” give an explicit instruction to the engine. The supported engine directives for each error. The different error strategies are described in the documentation.

  8. Set the DBMS Message property to Yes if you want the actual DBMS Message to be automatically displayed. This overrides the Display Full Messages setting in Settings->Environment->Preferences.

As you can see there are several different specific error types you can handle. You can also handle the type “Any Error” which will be triggered when any database error is generated.

Now you have a handler that will respond to the selected error. You can add operations to handle the error.

If you add no operations, and Directive=Ignore, then the error will just be blocked. You may choose to do this in situations where you know there will be errors that don’t matter, such as when you are loading records where some might be duplicates. The duplicates will generate an error and will not be loaded, but you will not have to bother the user with an error message.

One of the things you can do in the handler is to display an error message to the user, or to put an error message into a log. Magic xpa has a series of functions, such as ErrDatabaseName, ErrDbmsCode, ErrTableName, and ErrDbmsMessage, that can be used to display or save information about the error. However, if you set the DBMS Message property to Yes, then the message buffer will be cleared after the message is displayed to the user, and the DbErr and ErrDbmsMessage functions will return an empty string. So, if you want to use the DBMS error information in your program and also display it to the user, set the DBMS Message property to No, and display the message manually using a Verify operation.

See also

The Online and Rich Client Samples projects (program SQ02 and RSQ02)

Reference
Attachment 
Attachment