diff options
author | Brian Hinz <bphinz@users.sourceforge.net> | 2012-12-16 20:35:39 +0000 |
---|---|---|
committer | Brian Hinz <bphinz@users.sourceforge.net> | 2012-12-16 20:35:39 +0000 |
commit | 504d98fcaa0c9571e3fb011947fa1a1e1d263237 (patch) | |
tree | c1297c2f593f6871e2f9e9e77c12994b98e9ac0d /java | |
parent | d93a26d665b18b0e779c524f54c7acdc18898b94 (diff) | |
download | tigervnc-504d98fcaa0c9571e3fb011947fa1a1e1d263237.tar.gz tigervnc-504d98fcaa0c9571e3fb011947fa1a1e1d263237.zip |
Make exception handling more user friendly. Not all exceptions are 'errors' (for example, exiting the server intentionally via the window manager's logoff button).
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@5021 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'java')
-rw-r--r-- | java/com/tigervnc/network/SocketDescriptor.java | 24 | ||||
-rw-r--r-- | java/com/tigervnc/network/TcpListener.java | 6 | ||||
-rw-r--r-- | java/com/tigervnc/network/TcpSocket.java | 6 | ||||
-rw-r--r-- | java/com/tigervnc/rdr/FdOutStream.java | 4 | ||||
-rw-r--r-- | java/com/tigervnc/rdr/TLSOutStream.java | 2 | ||||
-rw-r--r-- | java/com/tigervnc/vncviewer/CConn.java | 8 | ||||
-rw-r--r-- | java/com/tigervnc/vncviewer/VncViewer.java | 16 |
7 files changed, 36 insertions, 30 deletions
diff --git a/java/com/tigervnc/network/SocketDescriptor.java b/java/com/tigervnc/network/SocketDescriptor.java index 4c5a23af..22f0a3d8 100644 --- a/java/com/tigervnc/network/SocketDescriptor.java +++ b/java/com/tigervnc/network/SocketDescriptor.java @@ -39,13 +39,13 @@ public class SocketDescriptor implements FileDescriptor { writeSelector = Selector.open(); readSelector = Selector.open(); } catch (IOException e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } try { channel.register(writeSelector, SelectionKey.OP_WRITE); channel.register(readSelector, SelectionKey.OP_READ); } catch (java.nio.channels.ClosedChannelException e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } } @@ -54,7 +54,7 @@ public class SocketDescriptor implements FileDescriptor { channel.socket().shutdownInput(); channel.socket().shutdownOutput(); } catch(IOException e) { - throw new IOException(e.toString()); + throw new IOException(e.getMessage()); } } @@ -62,7 +62,7 @@ public class SocketDescriptor implements FileDescriptor { try { channel.close(); } catch(IOException e) { - throw new IOException(e.toString()); + throw new IOException(e.getMessage()); } } @@ -80,7 +80,7 @@ public class SocketDescriptor implements FileDescriptor { try { n = channel.read(b); } catch (java.io.IOException e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } if (n <= 0) return (n == 0) ? -1 : 0; @@ -99,7 +99,7 @@ public class SocketDescriptor implements FileDescriptor { try { n = channel.write(b); } catch (java.io.IOException e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } b.clear(); return n; @@ -129,7 +129,7 @@ public class SocketDescriptor implements FileDescriptor { } } } catch (java.io.IOException e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } return n; } @@ -139,7 +139,7 @@ public class SocketDescriptor implements FileDescriptor { try { n = channel.write(buf); } catch (java.io.IOException e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } return n; } @@ -151,7 +151,7 @@ public class SocketDescriptor implements FileDescriptor { try { n = channel.write(buf, offset, length); } catch (java.io.IOException e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } return n; } @@ -161,7 +161,7 @@ public class SocketDescriptor implements FileDescriptor { try { n = channel.read(buf); } catch (java.io.IOException e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } return n; } @@ -173,7 +173,7 @@ public class SocketDescriptor implements FileDescriptor { try { n = channel.read(buf, offset, length); } catch (java.io.IOException e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } return n; } @@ -232,7 +232,7 @@ public class SocketDescriptor implements FileDescriptor { writeSelector = Selector.open(); readSelector = Selector.open(); } catch (java.io.IOException e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } try { channel.register(writeSelector, SelectionKey.OP_WRITE); diff --git a/java/com/tigervnc/network/TcpListener.java b/java/com/tigervnc/network/TcpListener.java index d56cd065..e6588699 100644 --- a/java/com/tigervnc/network/TcpListener.java +++ b/java/com/tigervnc/network/TcpListener.java @@ -62,7 +62,7 @@ public class TcpListener extends SocketListener { addr = InetAddress.getByName("0.0.0.0"); } } catch (UnknownHostException e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } try { @@ -120,7 +120,7 @@ public class TcpListener extends SocketListener { try { new_sock.socket().setTcpNoDelay(true); } catch (java.net.SocketException e) { - throw new SocketException(e.toString()); + throw new SocketException(e.getMessage()); } // Create the socket object & check connection is allowed @@ -128,7 +128,7 @@ public class TcpListener extends SocketListener { try { fd = new SocketDescriptor(); } catch (java.lang.Exception e) { - throw new SocketException(e.toString()); + throw new SocketException(e.getMessage()); } fd.setChannel(new_sock); TcpSocket s = new TcpSocket(fd); diff --git a/java/com/tigervnc/network/TcpSocket.java b/java/com/tigervnc/network/TcpSocket.java index cdc05016..bd5fe2b2 100644 --- a/java/com/tigervnc/network/TcpSocket.java +++ b/java/com/tigervnc/network/TcpSocket.java @@ -108,7 +108,7 @@ public class TcpSocket extends Socket { try { ((SocketDescriptor)getFd()).close(); } catch (IOException e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } } @@ -148,7 +148,7 @@ public class TcpSocket extends Socket { SocketAddress myaddr = ((SocketDescriptor)getFd()).getLocalAddress(); return myaddr.equals(peeraddr); } catch (IOException e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } } @@ -157,7 +157,7 @@ public class TcpSocket extends Socket { try { ((SocketDescriptor)getFd()).shutdown(); } catch (IOException e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } } diff --git a/java/com/tigervnc/rdr/FdOutStream.java b/java/com/tigervnc/rdr/FdOutStream.java index e5a55e0d..56b660fa 100644 --- a/java/com/tigervnc/rdr/FdOutStream.java +++ b/java/com/tigervnc/rdr/FdOutStream.java @@ -107,7 +107,7 @@ public class FdOutStream extends OutStream { n = fd.select(SelectionKey.OP_WRITE, tv); } catch (java.lang.Exception e) { System.out.println(e.toString()); - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } } while (n < 0); @@ -117,7 +117,7 @@ public class FdOutStream extends OutStream { try { n = fd.write(data, dataPtr, length); } catch (java.lang.Exception e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } return n; diff --git a/java/com/tigervnc/rdr/TLSOutStream.java b/java/com/tigervnc/rdr/TLSOutStream.java index 355df817..61296525 100644 --- a/java/com/tigervnc/rdr/TLSOutStream.java +++ b/java/com/tigervnc/rdr/TLSOutStream.java @@ -79,7 +79,7 @@ public class TLSOutStream extends OutStream { try { n = manager.write(data, dataPtr, length); } catch (java.io.IOException e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } //if (n == GNUTLS_E_INTERRUPTED || n == GNUTLS_E_AGAIN) // return 0; diff --git a/java/com/tigervnc/vncviewer/CConn.java b/java/com/tigervnc/vncviewer/CConn.java index e51cb444..610aef98 100644 --- a/java/com/tigervnc/vncviewer/CConn.java +++ b/java/com/tigervnc/vncviewer/CConn.java @@ -134,7 +134,7 @@ public class CConn extends CConnection try { sock = new TcpSocket(serverHost, serverPort); } catch (java.lang.Exception e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } vlog.info("connected to host "+serverHost+" port "+serverPort); } @@ -177,7 +177,7 @@ public class CConn extends CConnection wait(1); } } catch (java.lang.InterruptedException e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } } @@ -299,7 +299,7 @@ public class CConn extends CConnection vlog.info("Redirected to "+host+":"+port); VncViewer.newViewer(viewer, sock, true); } catch (java.lang.Exception e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } } @@ -698,7 +698,7 @@ public class CConn extends CConnection if (sock != null) sock.shutdown(); } catch (java.lang.Exception e) { - throw new Exception(e.toString()); + throw new Exception(e.getMessage()); } } diff --git a/java/com/tigervnc/vncviewer/VncViewer.java b/java/com/tigervnc/vncviewer/VncViewer.java index cf38760f..ebd90b47 100644 --- a/java/com/tigervnc/vncviewer/VncViewer.java +++ b/java/com/tigervnc/vncviewer/VncViewer.java @@ -371,12 +371,18 @@ public class VncViewer extends java.applet.Applet implements Runnable while (!cc.shuttingDown) cc.processMsg(); } catch (java.lang.Exception e) { - if (cc == null || !cc.shuttingDown) { + if (e instanceof EndOfStream) { + vlog.info(e.getMessage()); + } else if (cc == null || !cc.shuttingDown) { e.printStackTrace(); - JOptionPane.showMessageDialog(null, - e.toString(), - "VNC Viewer : Error", - JOptionPane.ERROR_MESSAGE); + JOptionPane op = + new JOptionPane(e.getMessage(), JOptionPane.WARNING_MESSAGE); + JDialog dlg = op.createDialog("TigerVNC Viewer"); + ClassLoader cl = this.getClass().getClassLoader(); + ImageIcon icon = + new ImageIcon(cl.getResource("com/tigervnc/vncviewer/tigervnc.ico")); + dlg.setIconImage(icon.getImage()); + dlg.setVisible(true); } else { if (!cc.shuttingDown) vlog.info(e.toString()); |