package org.nwapw.abacus.number;

public abstract class Function {

    public int arity;

    protected abstract Number applyInternal(Number...params);

    public Number apply(Number...params) throws IllegalArgumentException {
        if(params.length != arity)
            throw new IllegalArgumentException("Invalid number of arguments: Function takes "
                    + arity + ", " + params.length + " provided.");
        return applyInternal(params);
    }

}

package org.nwapw.abacus.number;

public abstract class Function {

    protected abstract boolean matchesParams(Number[] params);
    protected abstract Number applyInternal(Number[] params);

    public Number apply(Number...params) {
        if(!matchesParams(params)) return null;
        return applyInternal(params);
    }

}

Change function to return null on error, and change arity checks.
Change function to return null on error, and change arity checks.
