/**
* This file is part of Erjang - A JVM-based Erlang VM
*
* Copyright (c) 2009 by Trifork
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package erjang;
/**
* Exception generated by erlang:error
*/
@SuppressWarnings("serial")
public class ErlangError extends ErlangException {
private ESeq args;
public EAtom getExClass() { return am_error; }
public ErlangError(Throwable cause) {
super(cause);
}
public ErlangError(EObject reason) {
super(reason);
}
public ErlangError(EObject reason, ESeq args) {
super(reason);
this.args = args;
}
public ErlangError(EObject reason, EObject... args) {
super(reason);
this.args = ESeq.fromArray(args);
}
public ErlangError(EObject reason, Throwable cause, EObject... args) {
super(reason, cause);
this.args = ESeq.fromArray(args);
}
/*
* (non-Javadoc)
*
* @see erjang.ErlangException#reason()
*/
@Override
public EObject reason() {
ETuple2 val = new ETuple2(super.reason(), getTrace());
return val;
}
public ESeq getTrace() {
ESeq trace = super.getTrace();
if (args != null && !trace.isNil()) {
ETuple4 first = ETuple4.cast(trace.head().testTuple());
ESeq res = trace.tail().testSeq();
ETuple4 fa = new ETuple4();
fa.elem1 = first.elem1;
fa.elem2 = first.elem2;
fa.elem3 = args;
fa.elem4 = first.elem4;
trace = res.cons(fa);
}
return trace;
}
}