try{}catch(){} with RMI

Discussion in 'Java' started by Nancy.Nicole@gmail.com, Aug 16, 2006.

  1. Guest

    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...
     
    , Aug 16, 2006
    #1
    1. Advertising

  2. Oliver Wong Guest

    <> wrote in message
    news:...
    > 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/Su...estions_20on_20Newsgroups#RepeatErrorsExactly

    - Oliver
     
    Oliver Wong, Aug 16, 2006
    #2
    1. Advertising

  3. Eric Sosman Guest

    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.

    --
     
    Eric Sosman, Aug 16, 2006
    #3
  4. <> 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
     
    Thomas Fritsch, Aug 17, 2006
    #4
  5. Guest


    > >

    > 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?
     
    , Aug 17, 2006
    #5
  6. Oliver Wong Guest

    <> wrote in message
    news:...
    >
    >> >

    >> 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
     
    Oliver Wong, Aug 17, 2006
    #6
  7. Guest


    >
    > 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!
     
    , Aug 17, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bienwell
    Replies:
    4
    Views:
    3,872
    bienwell
    May 27, 2005
  2. Buu Nguyen

    RMI, JINI or RMI/IIOP

    Buu Nguyen, Aug 25, 2004, in forum: Java
    Replies:
    1
    Views:
    581
    Sudsy
    Aug 25, 2004
  3. JScoobyCed

    RMI Vs RMI over IIOP

    JScoobyCed, Jan 28, 2005, in forum: Java
    Replies:
    1
    Views:
    756
    Dag Sunde
    Jan 28, 2005
  4. Jan Schulze
    Replies:
    1
    Views:
    582
    Esmond Pitt
    Mar 26, 2005
  5. John Salerno
    Replies:
    20
    Views:
    868
    John Salerno
    Aug 11, 2006
Loading...

Share This Page