What i do (not sure is the best way but it works):
Every form has en errormessages text area 
The forms classs inherit from a super class with  getter and setter methods for 
the textarea
In the action class when an exception is raised i fill the form textarea with 
the error messages.


Hih
Marcello


-----Messaggio originale-----
Da: Francisco Exposito Aguilera [mailto:[EMAIL PROTECTED] 
Inviato: domenica 4 febbraio 2007 18.01
A: user@struts.apache.org
Oggetto: Exceptions design

Hello all,

I have a doubt about how design the exceptions in my struts project. I have the 
action classes and the bean classes. The action classes execute methods from 
bean classes, which connect to the database.

Supposing I am trying to create a user in one of my web pages and the user I 
want to create exists. What is the best way to show the user this sql error?

1.Throw the exception in the bean class to the struts ModuleException and show 
a typical error page. (I hope this is not the best way because I don´t like it).

2.Before execute the createUser bean method, execute another method to check if 
the user already exists. If it exists, use ActionMessages in the action class 
to show the error in the same createUser.jsp file.

That means that if the user doesn´t exist, the action method will access, at 
least twice to the database, one for check if the user exists and one for 
create it.

3.Execute the createUser bean method using try and finally but without catch; 
and throw the SQL exception.

public OTDUser validUser (String dni, String passwd) throws SQLException {
        try
        {
                Connection to the database and results
        }
        finally
        {
                Close resultSet, statement and connection
        }
}

The exception will be catched by the action class, where there is a 
catch(SQLException), which will receive the exception from the bean method

java.sql.SQLException: ORA-00001: unique restriction (PK_USER) violated

And with ActionMessages show it in the same createUser.jsp. But now, can I know 
if the SQLException is caused by:

a) Primary key is violated (java.sql.SQLException: ORA-00001: unique 
restriction (PK_USER) violated)

b) Name and both surnames are unique (java.sql.SQLException: ORA-00001: 
unique restriction (U_NAME_SURNAME1_SURNAME2_U) violated)

Depending on the exception, I want to show "primary key exists" or "name and 
surnames exists with another primary key"

4.Any suggestion?

Thanks a lot.

_________________________________________________________________
Horóscopo, tarot, numerología... Escucha lo que te dicen los astros. 
http://astrocentro.msn.es/


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to