• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Errors from server to client

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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/
 
beda meda
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic