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

[Prev: switch] [Home] [Next: try]

throw

try {
    Statements;
    throw "an exception";
}
catch ( e ) {
    if ( e == "an exception" ) {
        ExceptionStatements;
    }
    else {
        OtherExceptionStatements
    }
}

The throw keyword is used to raise user-defined exceptions.

Example:

    function monthToName( i )
    {
        var IndexToMonth = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
                             "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
        
        if ( i < 0 || i > 11 ) {
            throw "month number out of range";
        }
        else {
            return IndexToMonth[ i ];
        }
    }

It is also possible to define a user-defined exception class and throw an object of that type, e.g.

    throw new AUserDefinedException( "month number out of range" );

See also try.

[Prev: switch] [Home] [Next: try]


Copyright © 2001-2006 TrolltechTrademarks
QSA version 1.1.5