Remove I18nException

This commit is contained in:
yushijinhun 2018-07-01 21:40:09 +08:00
parent 13e931cda4
commit 7583f4651d
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
2 changed files with 11 additions and 59 deletions

View File

@ -40,7 +40,6 @@ import org.jackhuang.hmcl.ui.LogWindow;
import org.jackhuang.hmcl.ui.construct.MessageBox;
import org.jackhuang.hmcl.ui.construct.TaskExecutorDialogPane;
import org.jackhuang.hmcl.util.*;
import org.jackhuang.hmcl.util.i18n.I18nException;
import java.io.File;
import java.io.IOException;
@ -182,10 +181,17 @@ public final class LauncherHelper {
Exception ex = executor.getLastException();
if (ex != null) {
String message;
if (ex instanceof CurseCompletionException)
if (ex instanceof CurseCompletionException) {
message = i18n("modpack.type.curse.error");
else
message = I18nException.getStackTrace(ex);
} else if (ex instanceof PermissionException) {
message = i18n("launch.failed.executable_permission");
} else if (ex instanceof ProcessCreationException) {
message = i18n("launch.failed.creating_process") + ex.getLocalizedMessage();
} else if (ex instanceof NotDecompressingNativesException) {
message = i18n("launch.failed.decompressing_natives") + ex.getLocalizedMessage();
} else {
message = StringUtils.getStackTrace(ex);
}
Controllers.dialog(message,
scriptFile == null ? i18n("launch.failed") : i18n("version.launch_script.failed"),
MessageBox.ERROR_MESSAGE);
@ -298,15 +304,7 @@ public final class LauncherHelper {
@Override
public void execute() throws Exception {
try {
setResult(supplier.get());
} catch (PermissionException e) {
throw new I18nException(i18n("launch.failed.executable_permission"), e);
} catch (ProcessCreationException e) {
throw new I18nException(i18n("launch.failed.creating_process") + e.getLocalizedMessage(), e);
} catch (NotDecompressingNativesException e) {
throw new I18nException(i18n("launch.failed.decompressing_natives") + e.getLocalizedMessage(), e);
}
setResult(supplier.get());
}
@Override

View File

@ -1,46 +0,0 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2018 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hmcl.util.i18n;
import org.jackhuang.hmcl.util.StringUtils;
public class I18nException extends Exception {
private final String localizedMessage;
public I18nException(String localizedMessage) {
this.localizedMessage = localizedMessage;
}
public I18nException(String localizedMessage, Throwable suppressed) {
addSuppressed(suppressed);
this.localizedMessage = localizedMessage;
}
@Override
public String getLocalizedMessage() {
return localizedMessage;
}
public static String getStackTrace(Throwable e) {
if (e instanceof I18nException)
return e.getLocalizedMessage();
else
return StringUtils.getStackTrace(e);
}
}