Improve error reporting in the branch dialog
[egit/imyousuf.git] / org.spearce.egit.core / src / org / spearce / egit / core / GitException.java
blob4724b22bfc6998c3b34926f67f2fcb4b121c616a
1 /*******************************************************************************
2 * Copyright (c) 2000, 2007 IBM Corporation and others.
3 * Copyright (c) 2003, 2006 Subclipse project and others.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * See LICENSE for the full license text, also available.
8 *******************************************************************************/
10 package org.spearce.egit.core;
12 import java.io.IOException;
13 import java.lang.reflect.InvocationTargetException;
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.team.core.TeamException;
18 import org.eclipse.team.core.TeamStatus;
20 /**
21 * A checked exception representing a failure in the Git plugin.
22 * <p>
23 * Git exceptions contain a status object describing the cause of the exception.
24 * </p>
26 * @see IStatus
28 public class GitException extends TeamException {
30 private static final long serialVersionUID = 1L;
32 /**
33 * Constructs a new Git exception
35 * @param severity
36 * @param code
37 * @param message
38 * @param e
40 public GitException(int severity, int code, String message, Throwable e) {
41 super(new TeamStatus(severity, Activator.getPluginId(), code, message,
42 e, null));
45 /**
46 * Constructs a new Git exception
48 * @param severity
49 * @param code
50 * @param message
52 public GitException(int severity, int code, String message) {
53 this(severity, code, message, null);
56 /**
57 * Constructs a new Git exception
59 * @param message
60 * @param e
62 public GitException(String message, Throwable e) {
63 this(IStatus.ERROR, UNABLE, message, e);
66 /**
67 * Constructs a new Git exception
69 * @param message
71 public GitException(String message) {
72 this(message, null);
75 /**
76 * Constructs a new Git exception
78 * @param status
80 public GitException(IStatus status) {
81 super(status);
84 /**
85 * Transform this exception into a CoreException
87 * @return the new CoreException
89 public CoreException toCoreException() {
90 IStatus status = getStatus();
91 return new CoreException(new Status(status.getSeverity(), status
92 .getPlugin(), 0, status.getMessage(), this));
95 /**
96 * Static helper method for creating a Git exception
98 * @param resource
99 * @param message
100 * @param e
101 * @return the created exception
103 public static GitException wrapException(IResource resource,
104 String message, CoreException e) {
105 return new GitException(IStatus.ERROR, e.getStatus().getCode(),
106 message, e);
110 * Static helper method for creating a Git exception
112 * @param e
113 * @return the created exception
115 public static GitException wrapException(Exception e) {
116 Throwable t = e;
117 if (e instanceof InvocationTargetException) {
118 Throwable target = ((InvocationTargetException) e)
119 .getTargetException();
120 if (target instanceof GitException) {
121 return (GitException) target;
123 t = target;
126 return new GitException(IStatus.ERROR, UNABLE,
127 t.getMessage() != null ? t.getMessage() : "", t); //$NON-NLS-1$
131 * Static helper method for creating a Git exception
133 * @param e
134 * @return the created exception
136 public static GitException wrapException(CoreException e) {
137 IStatus status = e.getStatus();
138 if (!status.isMultiStatus()) {
139 status = new TeamStatus(status.getSeverity(), Activator
140 .getPluginId(), status.getCode(), status.getMessage(), e,
141 null);
143 return new GitException(status);
147 * Static helper method for creating a Git exception
149 * @param e
150 * @return the created exception
152 public static GitException wrapException(IOException e) {
153 return new GitException(IStatus.ERROR, IO_FAILED, e.getMessage(), e);
157 * Static helper method for creating a Git exception
159 * @param e
160 * @return the created exception
162 public static GitException wrapException(TeamException e) {
163 if (e instanceof GitException)
164 return (GitException) e;
165 else
166 return new GitException(e.getStatus());