Try/Catch

The Try/Catch function create a customized error handling system that is called whenever a runtime error occurs.

Category: Error Handling


Syntax:
    TRY
        // Procedure Statements...
    CATCH( object Err )
        // Error Handler Statements...
    END


Description:

The Try/Catch function create a structured exception handler allowing the use of user-defined error handlers.

Basically, a user brackets any code that has the potential to fail or generate an error with the TRY/CATCH functions. TRY/CATCH error handling can be nested for even greater error processing control.

If a TRY/CATCH segment of code fails, control is passed to the CATCH function with the Error object instantiated with the correpsonding error information. If no error occurs, control is passed to the next statement following the TRY/CATCH/END function.


Platforms:
    Windows, DOS, Internet Active Pages


Example:
  FUNCTION main( )
    local err
    
    TRY

        x = 20
        y = 0
        
        // this generates an error
        z = x / y
        
        return( 1 )

    
    CATCH ( err )
    	local s
    	
        s =  "Error [" + err.errornum + "]"
        s += "at line #" + err.errorline
        s += " (" + ErrorAsText( err.errornum ) + ")"

        msgDelay( 3000, s )

        return( 0 )
    END

  END

  
(c) 2000-2001 by West Coast Web Adventures, Inc., All Rights Reserved