views:

1685

answers:

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.

+1  A: 

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

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

dfrankow
+2  A: 

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.

Hugo
*WRONG* all classes have a constructor, you cant compile one without. GWT requires a no arguments constructor which doesnt have to be public.
mP
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.
Hugo
Where is this documented?
MTsoul
"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
Hugo