tikhomirov@148: /*
tikhomirov@394: * Copyright (c) 2011-2012 TMate Software Ltd
tikhomirov@148: *
tikhomirov@148: * This program is free software; you can redistribute it and/or modify
tikhomirov@148: * it under the terms of the GNU General Public License as published by
tikhomirov@148: * the Free Software Foundation; version 2 of the License.
tikhomirov@148: *
tikhomirov@148: * This program is distributed in the hope that it will be useful,
tikhomirov@148: * but WITHOUT ANY WARRANTY; without even the implied warranty of
tikhomirov@148: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
tikhomirov@148: * GNU General Public License for more details.
tikhomirov@148: *
tikhomirov@148: * For information on how to redistribute this software under
tikhomirov@148: * the terms of a license other than GNU General Public License
tikhomirov@148: * contact TMate Software at support@hg4j.com
tikhomirov@148: */
tikhomirov@148: package org.tmatesoft.hg.core;
tikhomirov@148:
tikhomirov@403: import org.tmatesoft.hg.internal.ExceptionInfo;
tikhomirov@275: import org.tmatesoft.hg.repo.HgRepository;
tikhomirov@275: import org.tmatesoft.hg.util.Path;
tikhomirov@275:
tikhomirov@148: /**
tikhomirov@425: * Root class for all Hg4J checked exceptions.
tikhomirov@148: *
tikhomirov@148: * @author Artem Tikhomirov
tikhomirov@148: * @author TMate Software Ltd.
tikhomirov@148: */
tikhomirov@148: @SuppressWarnings("serial")
tikhomirov@148: public class HgException extends Exception {
tikhomirov@403:
tikhomirov@403: protected final ExceptionInfo extras = new ExceptionInfo(this);
tikhomirov@275:
tikhomirov@148: public HgException(String reason) {
tikhomirov@148: super(reason);
tikhomirov@148: }
tikhomirov@148:
tikhomirov@148: public HgException(String reason, Throwable cause) {
tikhomirov@148: super(reason, cause);
tikhomirov@148: }
tikhomirov@148:
tikhomirov@148: public HgException(Throwable cause) {
tikhomirov@148: super(cause);
tikhomirov@148: }
tikhomirov@148:
tikhomirov@275: /**
tikhomirov@368: * @return not {@link HgRepository#BAD_REVISION} only when revision index was supplied at the construction time
tikhomirov@275: */
tikhomirov@367: public int getRevisionIndex() {
tikhomirov@403: return extras.getRevisionIndex();
tikhomirov@275: }
tikhomirov@275:
tikhomirov@367: public HgException setRevisionIndex(int rev) {
tikhomirov@403: return extras.setRevisionIndex(rev);
tikhomirov@275: }
tikhomirov@367:
tikhomirov@396: public boolean isRevisionIndexSet() {
tikhomirov@403: return extras.isRevisionIndexSet();
tikhomirov@396: }
tikhomirov@396:
tikhomirov@367: /**
tikhomirov@275: * @return non-null only when revision was supplied at construction time
tikhomirov@275: */
tikhomirov@275: public Nodeid getRevision() {
tikhomirov@403: return extras.getRevision();
tikhomirov@275: }
tikhomirov@275:
tikhomirov@275: public HgException setRevision(Nodeid r) {
tikhomirov@403: return extras.setRevision(r);
tikhomirov@275: }
tikhomirov@396:
tikhomirov@396: public boolean isRevisionSet() {
tikhomirov@403: return extras.isRevisionSet();
tikhomirov@396: }
tikhomirov@275:
tikhomirov@275: /**
tikhomirov@275: * @return non-null only if file name was set at construction time
tikhomirov@275: */
tikhomirov@275: public Path getFileName() {
tikhomirov@403: return extras.getFileName();
tikhomirov@275: }
tikhomirov@275:
tikhomirov@275: public HgException setFileName(Path name) {
tikhomirov@403: return extras.setFileName(name);
tikhomirov@275: }
tikhomirov@275:
tikhomirov@320: @Override
tikhomirov@320: public String toString() {
tikhomirov@320: StringBuilder sb = new StringBuilder(super.toString());
tikhomirov@320: sb.append(' ');
tikhomirov@320: sb.append('(');
tikhomirov@403: extras.appendDetails(sb);
tikhomirov@320: sb.append(')');
tikhomirov@320: return sb.toString();
tikhomirov@320: }
tikhomirov@148: // /* XXX CONSIDER capability to pass extra information about errors */
tikhomirov@148: // public static class Status {
tikhomirov@148: // public Status(String message, Throwable cause, int errorCode, Object extraData) {
tikhomirov@148: // }
tikhomirov@148: // }
tikhomirov@148: }