blob: 73d26b09d7b2e56105c86641b56070195bb55a4c [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2009 Akos Horvath and Daniel Varro
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Akos Horvath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.gtasm.interpreter.exception;
import org.eclipse.emf.ecore.EObject;
/** A common supertype for all GTASM exceptions
* @author Akos Horvath
*
*/
public abstract class ViatraTransformationException extends Exception {
private static final long serialVersionUID = 3668689213176229953L;
// private ViatraTransformationException(String msg) {
// super(msg);
// }
/** Constructor for the common GTASM exception class
* @param msg The template of the exception message
* @param context The data elements to be used to instantiate the template. Can be null if no context parameter is defined
*
*/
public ViatraTransformationException(String msg, String[] context) {
super(bind(msg,context));
}
/** Constructor for the common GTASM exception class
* @param msg The template of the exception message
* @param context The data elements to be used to instantiate the template. Can be null if no context parameter is defined
* @param cause The internal exception identifiable as cause
*/
public ViatraTransformationException(String msg, String[] context, Throwable cause) {
super(bind(msg,context), cause);
}
/**
* Binding the '{n}' (n = 1..N) strings to contextual conditions in 'context'
* @param context : array of context-sensitive Strings
*/
private static String bind(String message, String[] context) {
String additionalError = "";
if(context == null) return message;
for(int i = 0; i<context.length; i++){
message = message.replace("{"+(i+1)+"}", context[i]!= null? context[i] : "<<null>>");
//error handling in case there is a null value in the context array
if(context[i] == null)
additionalError = "[INTERNAL ERROR] A name value in the GTASM model is null. \n\n";
}
return additionalError+message;
}
/**Tries to add a new element to the stack trace based on its input element
* @param element Element to be processed for source information
* @return
*/
public ViatraTransformationException addNewStackElement(EObject element){ return null;}
}