Introduce FatalException

Rather than throwing a generic RuntimeException for fatal / catastrophic
exceptions (which are typically due to developer error) throw
FatalException.
This commit is contained in:
Chris Beams 2014-11-03 17:56:36 +01:00
parent e08c2bb564
commit ce9aca0d1e
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
2 changed files with 35 additions and 1 deletions

View File

@ -0,0 +1,30 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare 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 Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare;
@SuppressWarnings("serializable")
public class FatalException extends RuntimeException {
public FatalException(String format, Object... args) {
super(String.format(format, args));
}
public FatalException(Throwable cause, String format, Object... args) {
super(String.format(format, args), cause);
}
}

View File

@ -17,6 +17,7 @@
package io.bitsquare.util;
import io.bitsquare.FatalException;
import io.bitsquare.gui.Navigation;
import io.bitsquare.locale.BSResources;
@ -56,6 +57,9 @@ public class ViewLoader {
public ViewLoader(Navigation.Item navItem, boolean useCaching) {
this.url = ViewLoader.class.getResource(navItem.getFxmlUrl());
if (this.url == null) {
throw new FatalException("'%s' could not be loaded as a resource", navItem.getFxmlUrl());
}
isCached = useCaching && cachedGUIItems.containsKey(url);
if (!isCached) {
@ -85,7 +89,7 @@ public class ViewLoader {
cachedGUIItems.put(url, item);
return result;
} catch (IOException e) {
throw new RuntimeException("Failed to load view at " + url, e);
throw new FatalException(e, "Failed to load view at %s", url);
}
}