> public boolean isDuplicateSsn(String ssn) throws SQLException
You can't throw a SQLException from a method of a RemoteServiceServlet.
To be able to transport this exception to the client (where it is passed
as argument to the onFailure-method of the AsyncCallback, it's necessary
to extend it from SerializableException which SQLException clearly isn't.
I solved it that way, that I throw a RemoteServiceException where I add
the stacktrace of the causing exception as String, allowing to show the
error in a usual way (if you want to show that much information to an
user) without the need to create many many different exceptions.
Regards, Lothar
> By the way, I could not find RemoteServiceException in GWT doc. So, I
> assume it's your custom exception, right?
That's correct. But it's nothing very secret happening there so I
can post it here without being sent to the south-east-end of Cuba ;-)
------snip
/**
* Exception that will be thrown if there was an error while performing
* remote functions on the server
* @author "Lothar Kimmeringer" <lot...@kimmeringer.de>
*
*/
public class RemoteServiceException extends SerializableException {
private String stackTrace;
private String message;
private static final long serialVersionUID = 2L;
/**
* Creates a new instance of RemoteServiceException
*/
public RemoteServiceException() {
super();
}
/**
* Creates a new instance of RemoteServiceException
* @param message The message indicating the reason for the exception
* @param cause The cause leading to the exception
*/
public RemoteServiceException(String message, String cause) {
super(message);
this.message = message;
stackTrace = cause;
}
/**
* Creates a new instance of RemoteServiceException
* @param message The message indicating the reason for the exception
*/
public RemoteServiceException(String message) {
super(message);
this.message = message;
}
/**
* Returns the stacktrace of the cause
* @return The cause
*/
public String getCauseStackTrace() {
return stackTrace;
}
/**
* Returns the message of the exception
*/
public String getMessage(){
return message;
}
}
------snip
You can get the stacktrace as string doing the following:
StringWriter sw = new StringWriter();
throwable.printStackTrace(new PrintWriter(sw));
String stacktrace = sw.toString();
You have to do it outside the above exception, because the exception above
must be in a client-package, i.e. you are restricted to the GWT Java
ruling out PrintWriter at least.
Regards, Lothar