2

I'm using GWT (currenly working with google's eclipse plugin), and I'm trying to throw an exception from the server to the client.

My exception is something like

class LoginException extends Exception implements IsSerializable

But I get (upon loading in hosted mode):

[ERROR] Errors in '[...]/src/myPackage/client/services/Session.java'

[ERROR] Line 25: No source code is available for type hugobarrera.gestorAlumnos.server.LoginException; did you forget to inherit a required module?

Session.java is:
[...]

public interface Session extends RemoteService {

[...] (Line 25:)

String newSession(String usr, String pwd) throws LoginException;

[...]

Where am I going wrong? I've read like a MILLION places where people have problems with throwing exceptions, but none of those solutions applied.

WhyNotHugo
  • 9,423
  • 6
  • 62
  • 70
  • 3
    Is LoginException in the same java package and project as the Session interface? – skaffman Jun 21 '09 at 21:13
  • It wasn't. Moving it to the same package solved the problem. Also, moving it to [...]services.exceptions also works :) You should post this as an answer rather than a comment (= – WhyNotHugo Jun 23 '09 at 04:46

2 Answers2

4

All classes that need to be serialized must be in the [...].client package or a sub package.

Apparently they may not have a constructor either.
[edit] You need to have a no-argument constructor in the serializable classes.

WhyNotHugo
  • 9,423
  • 6
  • 62
  • 70
  • 1
    *WRONG* all classes have a constructor, you cant compile one without. GWT requires a no arguments constructor which doesnt have to be public. – mP. Jul 01 '09 at 03:25
  • Sorry about that, it was the conclusion I'd made. I fixed the answer now :) Note that you CAN'T not-have a constructor, if you don't define any, the no-arg constructor is implicitly defined. – WhyNotHugo Jul 01 '09 at 13:33
  • "If a class contains no constructor declarations, then a default constructor that takes no parameters is automatically provided[...]" http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.8.9 More info(Actual source of link): http://stackoverflow.com/questions/525548/default-constructors-and-inheritance-in-java – WhyNotHugo Nov 07 '09 at 20:25
2

skaffman: LoginException was not in the same package as Session.

Hugo: Moving them to the same package solved the problem.

dfrankow
  • 20,191
  • 41
  • 152
  • 214