Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > try{}catch(){} with RMI

Reply
Thread Tools

try{}catch(){} with RMI

 
 
Nancy.Nicole@gmail.com
Guest
Posts: n/a
 
      08-16-2006
Everytime I try to connect with the server via RMI I get stuck in
catch().

try
{
GarageServerImpl g = new GarageServerImpl();
Naming.rebind("Serve", g); // sets the handle
System.out.println("GarageServer started and " +
"awaiting connections.");
}
catch (RemoteException er)
{
System.out.println(
"Exception in GarageServer.main: " + er);
}
catch (Exception err)
{
System.out.println(
"Exception occurred: " + err);
}
}

Help? I don't know how to fix...

 
Reply With Quote
 
 
 
 
Oliver Wong
Guest
Posts: n/a
 
      08-16-2006

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Everytime I try to connect with the server via RMI I get stuck in
> catch().
>
> try
> {
> GarageServerImpl g = new GarageServerImpl();
> Naming.rebind("Serve", g); // sets the handle
> System.out.println("GarageServer started and " +
> "awaiting connections.");
> }
> catch (RemoteException er)
> {
> System.out.println(
> "Exception in GarageServer.main: " + er);
> }
> catch (Exception err)
> {
> System.out.println(
> "Exception occurred: " + err);
> }
> }
>
> Help? I don't know how to fix...


If you're just going to display the exception, don't catch it at all.
Instead, throw it all the way up, and the JVM will eventually catch and
display the exception for you, with more detailed information (such as a
stack trace).

Once you have the stack trace, post it here. See
http://riters.com/JINX/index.cgi/Sug...tErrorsExactly

- Oliver

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      08-16-2006


http://www.velocityreviews.com/forums/(E-Mail Removed) wrote On 08/16/06 16:47,:
> Everytime I try to connect with the server via RMI I get stuck in
> catch().
>
> try
> {
> GarageServerImpl g = new GarageServerImpl();
> Naming.rebind("Serve", g); // sets the handle
> System.out.println("GarageServer started and " +
> "awaiting connections.");
> }
> catch (RemoteException er)
> {
> System.out.println(
> "Exception in GarageServer.main: " + er);
> }
> catch (Exception err)
> {
> System.out.println(
> "Exception occurred: " + err);
> }
> }
>
> Help? I don't know how to fix...


I don't know what's wrong, but here's a suggestion: Each
of those Exception objects carries a lot of information about
the exact nature of the error and where it occurred -- and
you're throwing most of it away. (And you've kept what little
remains hidden from the rest of us ...)

Discard those System.out.println() calls and use the
Exception objects' printStackTrace() methods instead, and
you're likely to learn lots more about the circumstances
of the problem.

--
(E-Mail Removed)

 
Reply With Quote
 
Thomas Fritsch
Guest
Posts: n/a
 
      08-16-2006
<(E-Mail Removed)> wrote:
> Everytime I try to connect with the server via RMI I get stuck in
> catch().
>
> try
> {
> GarageServerImpl g = new GarageServerImpl();
> Naming.rebind("Serve", g); // sets the handle
> System.out.println("GarageServer started and " +
> "awaiting connections.");
> }
> catch (RemoteException er)
> {
> System.out.println(
> "Exception in GarageServer.main: " + er);
> }
> catch (Exception err)
> {
> System.out.println(
> "Exception occurred: " + err);
> }
> }
>
> Help? I don't know how to fix...
>

You can declare your main method with a throws-clause:

public static void main(String args[]) throws Exception
{
GarageServerImpl g = new GarageServerImpl();
Naming.rebind("Serve", g); // sets the handle
System.out.println("GarageServer started and " +
"awaiting connections.");
}

This has two advantages: You don't need any try/catch at all,
and in case of exception the JVM will print the stack trace.

--
Thomas


 
Reply With Quote
 
Nancy.Nicole@gmail.com
Guest
Posts: n/a
 
      08-17-2006

> >

> You can declare your main method with a throws-clause:
>
> public static void main(String args[]) throws Exception
> {
> GarageServerImpl g = new GarageServerImpl();
> Naming.rebind("Serve", g); // sets the handle
> System.out.println("GarageServer started and " +
> "awaiting connections.");
> }
>
> This has two advantages: You don't need any try/catch at all,
> and in case of exception the JVM will print the stack trace.
>
> --
> Thomas



Okay, here's the problem with that:

All of this happens when the user clicks "Submit", which means
actionPerformed calls my getQuote() method which is what uses the
try{}catch(){}. actionPerformed cannot throw an exception (or so that
is what the command prompt declares).

I can't think of another way to get around it. Ideas?

 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      08-17-2006

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ps.com...
>
>> >

>> You can declare your main method with a throws-clause:
>>
>> public static void main(String args[]) throws Exception
>> {
>> GarageServerImpl g = new GarageServerImpl();
>> Naming.rebind("Serve", g); // sets the handle
>> System.out.println("GarageServer started and " +
>> "awaiting connections.");
>> }
>>
>> This has two advantages: You don't need any try/catch at all,
>> and in case of exception the JVM will print the stack trace.
>>
>> --
>> Thomas

>
>
> Okay, here's the problem with that:
>
> All of this happens when the user clicks "Submit", which means
> actionPerformed calls my getQuote() method which is what uses the
> try{}catch(){}. actionPerformed cannot throw an exception (or so that
> is what the command prompt declares).
>
> I can't think of another way to get around it. Ideas?
>


For debugging purposes, catch and rethrow as an error. E.g.

public yourMethod() {
try {
/*whatever*/
} catch (NameOfTheException e) {
throw new Error(e);
}
}

Once you find out more information about the exception, you can figure
out how to handle it properly, in which case you'd replace the "throw new
Error(e)" code with code that actually handles the error.

- Oliver

 
Reply With Quote
 
Nancy.Nicole@gmail.com
Guest
Posts: n/a
 
      08-17-2006

>
> Once you find out more information about the exception, you can figure
> out how to handle it properly, in which case you'd replace the "throw new
> Error(e)" code with code that actually handles the error.
>
> - Oliver



Okay, sorry, the server I'm using is secure and I was trying a port
that had not yet been set to forward to the server. Obviously I don't
know anything about netwoking. Thanks for all the help, guys!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does java.rmi.Naming not implement interface java.rmi.Registry? Jan Schulze Java 1 03-26-2005 07:45 AM
RMI Vs RMI over IIOP JScoobyCed Java 1 01-28-2005 09:54 AM
java.rmi support inside Visual J# .NET =?Utf-8?B?TmFpbmVzaCBKaGF2ZXJp?= ASP .Net 2 11-30-2004 02:21 PM
RMI, JINI or RMI/IIOP Buu Nguyen Java 1 08-25-2004 11:28 AM
Re: Should I use RMI? Linus Nikander Java 0 06-27-2003 11:35 AM



Advertisments