diff src/org/tmatesoft/hg/internal/CsetParamKeeper.java @ 628:6526d8adbc0f

Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 22 May 2013 15:52:31 +0200
parents 78a9e26e670d
children a20121a2bba6
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/CsetParamKeeper.java	Tue May 21 20:17:33 2013 +0200
+++ b/src/org/tmatesoft/hg/internal/CsetParamKeeper.java	Wed May 22 15:52:31 2013 +0200
@@ -23,6 +23,7 @@
 import org.tmatesoft.hg.core.Nodeid;
 import org.tmatesoft.hg.repo.HgInvalidRevisionException;
 import org.tmatesoft.hg.repo.HgRepository;
+import org.tmatesoft.hg.repo.HgRuntimeException;
 
 /**
  * Common code to keep changelog revision and to perform boundary check.
@@ -43,19 +44,25 @@
 			set(repo.getChangelog().getRevisionIndex(changeset));
 		} catch (HgInvalidRevisionException ex) {
 			throw new HgBadArgumentException("Can't find revision", ex).setRevision(changeset);
+		} catch (HgRuntimeException ex) {
+			throw new HgBadArgumentException(String.format("Can't initialize with revision %s", changeset.shortNotation()), ex);
 		}
 		return this;
 	}
 	
 	public CsetParamKeeper set(int changelogRevIndex) throws HgBadArgumentException {
-		int lastCsetIndex = repo.getChangelog().getLastRevision();
-		if (changelogRevIndex == HgRepository.TIP) {
-			changelogRevIndex = lastCsetIndex;
+		try {
+			int lastCsetIndex = repo.getChangelog().getLastRevision();
+			if (changelogRevIndex == HgRepository.TIP) {
+				changelogRevIndex = lastCsetIndex;
+			}
+			if (changelogRevIndex < 0 || changelogRevIndex > lastCsetIndex) {
+				throw new HgBadArgumentException(String.format("Bad revision index %d, value from [0..%d] expected", changelogRevIndex, lastCsetIndex), null).setRevisionIndex(changelogRevIndex);
+			}
+			doSet(changelogRevIndex);
+		} catch (HgRuntimeException ex) {
+			throw new HgBadArgumentException(String.format("Can't initialize with revision index %d", changelogRevIndex), ex);
 		}
-		if (changelogRevIndex < 0 || changelogRevIndex > lastCsetIndex) {
-			throw new HgBadArgumentException(String.format("Bad revision index %d, value from [0..%d] expected", changelogRevIndex, lastCsetIndex), null).setRevisionIndex(changelogRevIndex);
-		}
-		doSet(changelogRevIndex);
 		return this;
 	}
 	
@@ -74,7 +81,7 @@
 	 * @param defaultRevisionIndex value to return when no revision was set, may be {@link HgRepository#TIP} which gets translated to real index if used
 	 * @return changelog revision index if set, or defaultRevisionIndex value otherwise
 	 */
-	public int get(int defaultRevisionIndex) {
+	public int get(int defaultRevisionIndex) throws HgRuntimeException {
 		// XXX perhaps, shall translate other predefined constants (like WORKING COPY) here, too (e.g. for HgRevertCommand)
 		if (changelogRevisionIndex != BAD_REVISION || changelogRevisionIndex != TIP) {
 			return changelogRevisionIndex;