Skip to content
Benedict Allen edited this page Nov 15, 2015 · 6 revisions

Parameters library

The parameters library is a small utility to help with type checking function parameters.

Functions

check()

parameters.check( number argc, ... )

Throws an IncorrectParameterException when vararg does not match the expected pattern.

Explanation below.

checkConstructor()

parameters.checkConstructor( Class class, number argc, ... )

Throws an IncorrectConstructorException when vararg does not match the expected pattern.

Explanation below.


Both these functions are used to check arguments that are passed to a function. If the argument types are incorrect, they throw an exception. They take argc, which is the number of arguments the function being checked expects. checkConstructor() also takes the Class of the instance which is being constructed.

The vararg (...) are the arguments passed to the function being checked, and should be in triplets like this: string name, string/Class type, value. For example, if a function takes a number x, you could use:

parameters.check( 1, "x", "number", x )

or if it takes a Sheet child in a constructor:

parameters.checkConstructor( self.class, 1, "child", Sheet, child )

The parameters library ensures type safety across the framework. It is highly recommended to check for invalid arguments using the supplied functions, in order to maintain uniform exception handling throughout your Application.

Clone this wiki locally