|Home | Tutorial | Classes | Functions | QSA Workbench | Language | Qt API | QSA Articles | Qt Script for Applications |

[Prev: case] [Home] [Next: continue]

### catch

    try {
        Statements;
    }
    catch( exception ) {
        ExceptionStatements;
    }

This keyword is used in try statements. If an exception occurs, then the ExceptionStatements in a matching `catch` block are executed.

Catch blocks come in two varieties, unqualified and qualified. An unqualified `catch` block has the form:

        catch ( e ) {
            /* statements */
        }

and a qualified `catch` block has the form:

        catch ( e if e instanceOf RangeError ) {
            /* statements */
        }

The possible exception types are:

- EvalError -- the result of a failed eval() call.

- RangeError -- a result that is out of range, e.g. an array index to an element that isn't in the array.

- TypeError -- an attempt to perform an operation on an object of an inappropriate type.

- User defined exceptions -- exceptions that are objects of a user-defined type.

See try for an example.

[Prev: case] [Home] [Next: continue]