Results 1 to 2 of 2
- 02-05-2011, 11:17 PM #1
Member
- Join Date
- Dec 2010
- Location
- New Engaland
- Posts
- 11
- Rep Power
- 0
How to throw exception w/RMI from Server->Client w/o "nested exception..." mentioned
I have a Server throwing a custom exception defined:
to the Client via RMI, where the Client attempts to display the SecurityException:Java Code:package class.project; import java.rmi.RemoteException; public class SecurityException extends RemoteException { /** * Serializable class SecurityException requires declaring a static final serialVersionUID field of type long */ private static final long serialVersionUID = 1L; /** * Constructor used to pass msg String argument up to Exception class constructor. * * @param msg String argument 'msg' passed up to Exception class constructor */ public SecurityException(String msg) { super(msg); } }
And I am wondering how to only display the SecurityException details provided by the Server:Java Code:public static void performTestOne(ATM atm) { try { atm.getBalance(getAccountInfo(0000001, 5555)); } catch (Exception e) { System.out.println("Failed as expected: "+e); } }
Unfortunately I am getting the following output:Java Code:if ( !this.security.authenticateTransaction(account_info, account) ) { throw new SecurityException( "Unable to authenticate transaction. Invalid username/password combination." ); }
What I need to see is:Failed as expected: java.rmi.ServerException: RemoteException occurred in server thread; nested e
xception is:
class.project.SecurityException: Unable to authenticate transaction. Invalid username
/password combination.
Failed as expected: class.project.SecurityException: Unable to authenticate transaction. Invalid username
/password combination.
- 02-06-2011, 05:38 AM #2
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
Instead of
try...Java Code:System.out.println("Failed as expected: "+e);
Java Code:System.out.println("Failed as expected: "+e.getCause());
When a remote object throws an exception, it gets bundled into a java.rmi.ServerException as the 'detail' field. Also, you'll have to change your catch statement to specifically catch a ServerException instead of the more generic Exception for this to work.
Similar Threads
-
Exception in thread "main" java.lang Exception In InitializerError
By kenzo2009 in forum New To JavaReplies: 4Last Post: 10-25-2010, 07:42 PM -
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
By shantimudigonda in forum New To JavaReplies: 1Last Post: 11-20-2009, 07:58 PM -
Exception in thread "main" java.lang.NoClassDefFoundError: client
By fithous in forum New To JavaReplies: 1Last Post: 04-02-2009, 09:50 PM -
[SOLVED] pls help :S . "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerE
By ara in forum New To JavaReplies: 10Last Post: 01-29-2009, 08:00 AM -
Exception in thread "main" java.lang.NoClassDefFoundError: client Help
By b000m in forum New To JavaReplies: 6Last Post: 08-18-2008, 06:44 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks