Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/HgRuntimeException.java @ 423:9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 23 Mar 2012 22:51:18 +0100 |
parents | |
children | 48f993aa2f41 |
comparison
equal
deleted
inserted
replaced
422:5d1cc7366d04 | 423:9c9c442b5f2e |
---|---|
1 /* | |
2 * Copyright (c) 2012 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.repo; | |
18 | |
19 import org.tmatesoft.hg.core.Nodeid; | |
20 import org.tmatesoft.hg.internal.ExceptionInfo; | |
21 import org.tmatesoft.hg.util.Path; | |
22 | |
23 /** | |
24 * Almost any method in Hg4J low-level API may throw subclass of this exception to indicate unexpected | |
25 * state/condition encountered, flawed data or IO error. Since most cases can't be handled in a reasonable | |
26 * manner (other than catch all exceptions and tell client something went wrong), and propagating all possible | |
27 * exceptions up through API is dubious task, low-level exceptions are made runtime, rooting at this single class. | |
28 * | |
29 * <p>Hi-level api, {@link org.tmatesoft.hg.core}, where interaction with user-supplied values is more explicit, | |
30 * may follow different exception strategy. | |
31 * | |
32 * @author Artem Tikhomirov | |
33 * @author TMate Software Ltd. | |
34 */ | |
35 @SuppressWarnings("serial") | |
36 public abstract class HgRuntimeException extends RuntimeException { | |
37 | |
38 protected final ExceptionInfo<HgRuntimeException> details = new ExceptionInfo<HgRuntimeException>(this); | |
39 | |
40 protected HgRuntimeException(String reason, Throwable cause) { | |
41 super(reason, cause); | |
42 } | |
43 | |
44 /** | |
45 * @return {@link HgRepository#BAD_REVISION} unless revision index was set during exception instantiation | |
46 */ | |
47 public int getRevisionIndex() { | |
48 return details.getRevisionIndex(); | |
49 } | |
50 | |
51 public HgRuntimeException setRevisionIndex(int rev) { | |
52 return details.setRevisionIndex(rev); | |
53 } | |
54 | |
55 public boolean isRevisionIndexSet() { | |
56 return details.isRevisionIndexSet(); | |
57 } | |
58 | |
59 | |
60 /** | |
61 * @return non-<code>null</code> when revision was supplied at construction time | |
62 */ | |
63 public Nodeid getRevision() { | |
64 return details.getRevision(); | |
65 } | |
66 | |
67 public HgRuntimeException setRevision(Nodeid r) { | |
68 return details.setRevision(r); | |
69 } | |
70 | |
71 public boolean isRevisionSet() { | |
72 return details.isRevisionSet(); | |
73 } | |
74 | |
75 /** | |
76 * @return non-null only if file name was set at construction time | |
77 */ | |
78 public Path getFileName() { | |
79 return details.getFileName(); | |
80 } | |
81 | |
82 public HgRuntimeException setFileName(Path name) { | |
83 return details.setFileName(name); | |
84 } | |
85 | |
86 @Override | |
87 public String toString() { | |
88 StringBuilder sb = new StringBuilder(super.toString()); | |
89 sb.append(' '); | |
90 sb.append('('); | |
91 details.appendDetails(sb); | |
92 sb.append(')'); | |
93 return sb.toString(); | |
94 } | |
95 } |