/**
 * Copyright (C) 2002, Vanderbilt University
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions 
 * are met:
 *
 * 1.   Redistributions of source code must retain the above copyright 
 *      notice, this list of conditions and the following disclaimer.
 *
 * 2.   Redistributions in binary form must reproduce the above copyright 
 *      notice, this list of conditions and the following disclaimer in 
 *      the documentation and/or other materials provided with the 
 *      distribution.
 *
 * 3.   Neither the name of Vanderbilt University nor the names of its 
 *      contributors may be used to endorse or promote products derived 
 *      from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * @author Miklos Maroti
 */

package org.isis.jaut;

/**
 * A runtime exception thrown by an Automation application.
 */
public class InvokeException extends RuntimeException
{
	/**
	 * An error code identifying the error.
	 */
	protected int errorCode;

	/**
	 * A textual, human-readable name of the source of the the exception. Typically, this is the name of the application.
	 */
	protected String source;

	/**
	 * A textual, human-readable description of the error intended for the customer.
	 */
	protected String description;

	/**
	 * Creates an exception that occurred during {@link Dispatch#invoke}.
	 * The fields of this object correspond to the fields of the <code>EXCEPINFO</code> Automation structure.
	 *
	 * @param errorCode an error code identifying the error.
	 * @param source the source of the exception.
	 * @param description the description of the error.
	 */
	public InvokeException(int errorCode, String source, String description)
	{
		this.errorCode = errorCode;
		this.source = source;
		this.description = description;
	}

	/**
	 * Returns the detailed message string for this exception.
	 *
	 * @return the detailed error message, if available.
	 */
	public String getMessage()
	{
		return "Application exception from " + source + ": " + description +
			" (0x" + Integer.toHexString(errorCode) + ")";
	}

	/**
	 * Load the "jaut" library.
	 */
	static
	{
		System.loadLibrary("jaut");
	}
}
