diff --git a/src/main/java/au/com/southsky/jfreesane/SaneSession.java b/src/main/java/au/com/southsky/jfreesane/SaneSession.java
index <HASH>..<HASH> 100644
--- a/src/main/java/au/com/southsky/jfreesane/SaneSession.java
+++ b/src/main/java/au/com/southsky/jfreesane/SaneSession.java
@@ -183,14 +183,13 @@ public final class SaneSession implements Closeable {
     outputStream.flush();
 
     SaneWord status = inputStream.readWord();
+    SaneWord handle = inputStream.readWord();
+    String resource = inputStream.readString();
 
     if (status.integerValue() != 0) {
       throw new SaneException(SaneStatus.fromWireValue(status.integerValue()));
     }
 
-    SaneWord handle = inputStream.readWord();
-    String resource = inputStream.readString();
-
     if (!resource.isEmpty()) {
       authorize(resource);
       status = inputStream.readWord();
Don't leave stream in a bad state when session.open() throws (#<I>)