view src/nabble/naml/namespaces/TemplateException.java @ 62:4674ed7d56df default tip

remove n2
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 30 Sep 2023 20:25:29 -0600
parents 7ecd1a4ef557
children
line wrap: on
line source

package nabble.naml.namespaces;


public class TemplateException extends Exception {

	// this class is just to prevent constructor confusion with message
	protected static final class Name {
		private final String s;

		private Name(String s) {
			this.s = s;
		}
	}

	protected static Name name(String s) {
		return new Name(s);
	}


	private final String name;

	protected TemplateException(Name name) {
		this.name = name.s;
	}

	protected TemplateException(Name name,Exception cause) {
		super(cause.getMessage(),cause);
		this.name = name.s;
	}

	protected TemplateException(Name name,String msg) {
		super(msg);
		this.name = name.s;
	}

	protected TemplateException(Name name,String msg,Exception cause) {
		super(msg,cause);
		this.name = name.s;
	}

	public static TemplateException newInstance(String name) {
		return new TemplateException(name(name));
	}

	public static TemplateException newInstance(String name,Exception cause) {
		return new TemplateException(name(name),cause);
	}

	protected String getName() {
		return name;
	}

	public boolean isNamed(String name) {
		return this.name.equals(name);
	}

	public String toString() {
		String s = getClass().getName() + ": " + getName();
		String message = getLocalizedMessage();
		return (message != null) ? (s + ": " + message) : s;
	}

}