// Copyright (c) 1996-2002 Brian D. Carlstrom

package bdc.scheme.exception;

import bdc.scheme.SchemeException;
import bdc.scheme.Symbol;
import bdc.scheme.expression.Expression;
import bdc.scheme.expression.Procedure;
import bdc.util.Constants;
import bdc.util.Fmt;

public class ArgumentCountException extends SchemeException
{
    String location;
    int    expected;
    int    received;
    Object source;


    public ArgumentCountException (Procedure location,
                                   int       expected,
                                   int       received)
    {
        this(location.toString(), expected, received, location.toString());
    }

    public ArgumentCountException (Symbol location,
                                   int    expected,
                                   int    received,
                                   Object source)
    {
        this(location.toString(), expected, received, source);
    }

    private ArgumentCountException (String location,
                                    int    expected,
                                    int    received,
                                    Object source)
    {
        this.location = location;
        this.expected = expected;
        this.received = received;
        this.source   = source;
    }

    public String toString ()
    {
        return Fmt.S("%s arguments expected: %s received in %s\n%s",
                     Constants.getInteger(expected),
                     Constants.getInteger(received),
                     location,
                     Expression.stackTrace(source));
    }
}
