From 066a2be3801a225130fe83baa6b82433b8022469 Mon Sep 17 00:00:00 2001 From: Adam Murdoch Date: Mon, 3 Sep 2012 13:59:46 +1000 Subject: [PATCH] Improved error handling for case where native library for current architecture is not available. --- src/main/java/net/rubygrapefruit/platform/Native.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/rubygrapefruit/platform/Native.java b/src/main/java/net/rubygrapefruit/platform/Native.java index 96f3cba..ee299e0 100755 --- a/src/main/java/net/rubygrapefruit/platform/Native.java +++ b/src/main/java/net/rubygrapefruit/platform/Native.java @@ -42,6 +42,9 @@ public class Native { } else { libFile = new File("build/binaries/" + platform.getLibraryName()); } + if (!libFile.isFile()) { + throw new NativeIntegrationUnavailableException(String.format("Native library is not available for this operating system and architecture.")); + } System.load(libFile.getCanonicalPath()); int nativeVersion = NativeLibraryFunctions.getVersion(); if (nativeVersion != NativeLibraryFunctions.VERSION) { @@ -52,8 +55,8 @@ public class Native { loaded = true; } catch (NativeException e) { throw e; - } catch (Exception e) { - throw new NativeException("Failed to initialise native integration.", e); + } catch (Throwable t) { + throw new NativeException("Failed to initialise native integration.", t); } } } @@ -75,8 +78,8 @@ public class Native { return platform.get(type); } catch (NativeException e) { throw e; - } catch (Exception e) { - throw new NativeException(String.format("Failed to load native integration %s.", type.getSimpleName()), e); + } catch (Throwable t) { + throw new NativeException(String.format("Failed to load native integration %s.", type.getSimpleName()), t); } }