comparison src/org/tmatesoft/hg/repo/HgInvalidFileException.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 src/org/tmatesoft/hg/core/HgInvalidFileException.java@2747b0723867
children 95c2f43008bd
comparison
equal deleted inserted replaced
422:5d1cc7366d04 423:9c9c442b5f2e
1 /*
2 * Copyright (c) 2011-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 java.io.File;
20 import java.io.IOException;
21
22 /**
23 * Thrown when there are troubles working with local file. Most likely (but not necessarily) wraps IOException. Might be
24 * perceived as specialized IOException with optional File and other repository information.
25 *
26 * <b>Hg4J</b> tries to minimize chances for IOException to occur (i.e. {@link File#canRead()} is checked before attempt to
27 * read a file that might not exist, and doesn't use this exception to wrap each and any {@link IOException} source (e.g.
28 * <code>#close()</code> calls are unlikely to yield it), hence it is likely to address real cases when I/O error occurs.
29 *
30 * On the other hand, when a file is supposed to exist and be readable, this exception might get thrown as well to indicate
31 * that's not true.
32 *
33 * @author Artem Tikhomirov
34 * @author TMate Software Ltd.
35 */
36 @SuppressWarnings("serial")
37 public class HgInvalidFileException extends HgRuntimeException {
38 // IMPLEMENTATION NOTE: Once needed, there might be intermediate e.g. HgDataStreamException
39 // (between HgInvalidFileException and HgRuntimeException) to root data access exceptions
40 // that do not originate from local files but e.g. a connection
41
42 public HgInvalidFileException(String message, Throwable th) {
43 super(message, th);
44 }
45
46 public HgInvalidFileException(String message, Throwable th, File file) {
47 super(message, th);
48 details.setFile(file); // allows null
49 }
50
51 public HgInvalidFileException setFile(File file) {
52 assert file != null; // doesn't allow null not to clear file accidentally
53 details.setFile(file);
54 return this;
55 }
56
57 /**
58 * @return file object that causes troubles, or <code>null</code> if specific file is unknown
59 */
60 public File getFile() {
61 return details.getFile();
62 }
63 }