I'm a bit clueless on how to handle exceptions. What I've think so far is to use a custom error page for the users so they can't see the full exception for security reasons and log the exception in a .txt
file.
So this is how my DAO methods structure is:
try {
//stuff
}
catch (SQLException e) {
exceptionHandler(e);
throw new RuntimeException(e);
}
finally {
if (conn != null) {
try {
conn.close();
}
catch (SQLException e)
{}
}
}
And this is the method that handles all the exceptions:
public void exceptionHandler(SQLException e){
Logger logger = Logger.getAnonymousLogger();
logger.log(Level.SEVERE, "an exception was thrown", e);
try {
FileOutputStream fos;
fos = new FileOutputStream(new File("userDAOexceptions.txt"), true);
PrintStream ps = new PrintStream(fos);
e.printStackTrace(ps);
fos.close();
ps.close();
} catch (FileNotFoundException e1) {}
catch (IOException e1) {}
}
Is this considered a good way to handle exceptions in the DAO layer?