File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Distributed Java and the fly likes Errors from server to client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Errors from server to client" Watch "Errors from server to client" New topic
Author

Errors from server to client

beda meda
Greenhorn

Joined: Jul 15, 2010
Posts: 6
Hi!
I'm not sure if this question belongs here, but I'll give it try. Here is my RMI application:








Now I need to get those exceptions from server to client. How should I do that?
Edward Harned
Ranch Hand

Joined: Sep 19, 2005
Posts: 291

Passing data requires the data be serialized in both directions. The easiest way is to covert the messages to Strings and pass those to the client.

Next time only include the actual code that matters: http://sscce.org/


Ed's latest article: A Java Parallel Calamity http://coopsoft.com/ar/Calamity2Article.html
beda meda
Greenhorn

Joined: Jul 15, 2010
Posts: 6
Well, question is how:) Everything my server does is called from client. Now it should do something on its own, but it hasn't any reference to client. I was given hint that I can have some class MyErr on server side, which would wrap any exception that occurs there (e.g. MyErr(SQLException)), that would be wrapped in Remote exception RemoteException(MyErr(SQLException)),, that would be sent via RMI to Client and dealt with. But I"m not sure how to accomplish this.
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

(I would recommend you to brush up your basics by some sun tutorials or some good book)

RemoteException is not meant to throw business exceptions. In most of the cases, RemoteException will be throws when there is a communication problem.

In your case you can define an exception class, may be, MyServerException and add in the throws clause of all your server methods. Whenever, an exception occurs on the server side you will throw this exception.

beda meda wrote: I was given hint that I can have some class MyErr on server side, which would wrap any exception that occurs there (e.g. MyErr(SQLException)), that would be wrapped in Remote exception RemoteException(MyErr(SQLException)),, that would be sent via RMI to Client and dealt with. But I"m not sure how to accomplish this.


Any Exception class will have a constructor that also takes a Throwable. You can wrap any exception into your desired type by using such a constructor.


apigee, a better way to API!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Errors from server to client