Use try/multi-catch

Change-Id: Icf5042cccb0662d6bd53302800e03211af94c16d
This commit is contained in:
Urs Wolfer
2015-06-24 20:06:25 +02:00
committed by David Pursehouse
parent 8702786e5a
commit 64cfaf242d
39 changed files with 51 additions and 174 deletions

View File

@@ -203,11 +203,7 @@ public abstract class BaseCommand implements Command {
final CmdLineParser clp = newCmdLineParser(options);
try {
clp.parseArgument(argv);
} catch (IllegalArgumentException err) {
if (!clp.wasHelpRequestedByOption()) {
throw new UnloggedFailure(1, "fatal: " + err.getMessage());
}
} catch (CmdLineException err) {
} catch (IllegalArgumentException | CmdLineException err) {
if (!clp.wasHelpRequestedByOption()) {
throw new UnloggedFailure(1, "fatal: " + err.getMessage());
}

View File

@@ -195,9 +195,7 @@ class DatabasePubKeyAuth implements PublickeyAuthenticator {
try {
byte[] bin = Base64.decodeBase64(line.getBytes("ISO-8859-1"));
keys.add(new Buffer(bin).getRawPublicKey());
} catch (RuntimeException e) {
logBadKey(path, line, e);
} catch (SshException e) {
} catch (RuntimeException | SshException e) {
logBadKey(path, line, e);
}
}

View File

@@ -105,10 +105,7 @@ public class SshKeyCacheImpl implements SshKeyCache {
new AccountSshKey(id, SshUtil.toOpenSshPublicKey(encoded));
SshUtil.parse(key);
return key;
} catch (NoSuchAlgorithmException e) {
throw new InvalidSshKeyException();
} catch (InvalidKeySpecException e) {
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
throw new InvalidSshKeyException();
} catch (NoSuchProviderException e) {

View File

@@ -60,9 +60,7 @@ public class SshUtil {
}
final byte[] bin = Base64.decodeBase64(Constants.encodeASCII(s));
return new Buffer(bin).getRawPublicKey();
} catch (RuntimeException re) {
throw new InvalidKeySpecException("Cannot parse key", re);
} catch (SshException e) {
} catch (RuntimeException | SshException e) {
throw new InvalidKeySpecException("Cannot parse key", e);
}
}

View File

@@ -158,11 +158,7 @@ final class AdminSetParent extends SshCommand {
}
} catch (RepositoryNotFoundException notFound) {
err.append("error: Project ").append(name).append(" not found\n");
} catch (IOException e) {
final String msg = "Cannot update project " + name;
log.error(msg, e);
err.append("error: ").append(msg).append("\n");
} catch (ConfigInvalidException e) {
} catch (IOException | ConfigInvalidException e) {
final String msg = "Cannot update project " + name;
log.error(msg, e);
err.append("error: ").append(msg).append("\n");

View File

@@ -49,9 +49,7 @@ final class PluginReloadCommand extends SshCommand {
} else {
try {
loader.reload(names);
} catch (InvalidPluginException e) {
throw die(e.getMessage());
} catch (PluginInstallException e) {
} catch (InvalidPluginException | PluginInstallException e) {
throw die(e.getMessage());
}
}

View File

@@ -95,10 +95,7 @@ public class QueryShell {
db.close();
db = null;
}
} catch (OrmException err) {
out.println("fatal: Cannot open connection: " + err.getMessage());
} catch (SQLException err) {
} catch (OrmException | SQLException err) {
out.println("fatal: Cannot open connection: " + err.getMessage());
} finally {
out.flush();
@@ -123,10 +120,7 @@ public class QueryShell {
db.close();
db = null;
}
} catch (OrmException err) {
out.println("fatal: Cannot open connection: " + err.getMessage());
} catch (SQLException err) {
} catch (OrmException | SQLException err) {
out.println("fatal: Cannot open connection: " + err.getMessage());
} finally {
out.flush();

View File

@@ -161,11 +161,7 @@ final class SetProjectCommand extends SshCommand {
}
} catch (RepositoryNotFoundException notFound) {
err.append("error: Project ").append(name).append(" not found\n");
} catch (IOException e) {
final String msg = "Cannot update project " + name;
log.error(msg, e);
err.append("error: ").append(msg).append("\n");
} catch (ConfigInvalidException e) {
} catch (IOException | ConfigInvalidException e) {
final String msg = "Cannot update project " + name;
log.error(msg, e);
err.append("error: ").append(msg).append("\n");