diff options
author | Alex Gorrod <alexg@wiredtiger.com> | 2014-06-23 14:48:40 +1000 |
---|---|---|
committer | Alex Gorrod <alexg@wiredtiger.com> | 2014-06-23 14:48:40 +1000 |
commit | e04abd5cc6dd1b42932231ced1436be4437189e0 (patch) | |
tree | 91d6e65c207cbaeb2939b0b87923c9d54ebc3108 | |
parent | 402de76b40eb17fac9523292bc6fc4689a91a73d (diff) | |
download | mongo-e04abd5cc6dd1b42932231ced1436be4437189e0.tar.gz |
Update Java example to catch WiredTiger exceptions.
This is related to #1011, we should review it again if we decide
that our API should throw runtime exceptions.
-rw-r--r-- | examples/java/com/wiredtiger/examples/ex_access.java | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/examples/java/com/wiredtiger/examples/ex_access.java b/examples/java/com/wiredtiger/examples/ex_access.java index cf5c884b021..368f16d32bf 100644 --- a/examples/java/com/wiredtiger/examples/ex_access.java +++ b/examples/java/com/wiredtiger/examples/ex_access.java @@ -25,17 +25,25 @@ * OTHER DEALINGS IN THE SOFTWARE. * * ex_access.java - * demonstrates how to create and access a simple table. + * demonstrates how to create and access a simple table. */ package com.wiredtiger.examples; import com.wiredtiger.db.*; public class ex_access { public static void main(String[] args) { - Connection conn = wiredtiger.open("WT_HOME", "create"); - Session s = conn.open_session(null); - s.create("table:t", "key_format=S,value_format=u"); - Cursor c = s.open_cursor("table:t", null, null); + Connection conn; + Session s; + Cursor c; + try { + conn = wiredtiger.open("WT_HOME", "create"); + s = conn.open_session(null); + s.create("table:t", "key_format=S,value_format=u"); + c = s.open_cursor("table:t", null, null); + } catch (WiredTigerException wte) { + System.err.println("WiredTigerException: " + wte); + return; + } System.out.println("Key format: " + c.getKeyFormat()); System.out.println("Value format: " + c.getValueFormat()); try { @@ -47,7 +55,14 @@ public class ex_access { System.out.println("Got: " + c.getKeyString()); } } catch (WiredTigerPackingException wtpe) { + System.err.println("WiredTigerPackingException: " + wtpe); + } catch (WiredTigerException wte) { + System.err.println("WiredTigerException: " + wte); + } + try { + conn.close(null); + } catch (WiredTigerException wte) { + System.err.println("WiredTigerException: " + wte); } - conn.close(null); } } |