catch the exception thrown when database is not available in web.xml

Hi,

I have an app that uses a mysql database configured in the web.xml configuration file - a javax.servlet.jsp.jstl.sql.dataSource param

There have been occasions where that server has been down, and this causes the expected error stack trace to be dumped to the jsp page

Is there anywhere I can catch that exception in the jsp page, so the end user does not see that nasty error?

Thanks,

Tom

[430 byte] By [tomhollanda] at [2007-10-3 0:28:55]
# 1

You have answered your own question, catch the exception with a try catch block !!

try

{

// doing something stupid

}

catch (Exception exception)

{

out.println("sorry user, you did something really stupid");

// it is acceptable to do nothing here if you dont want to handle the

// error or output a message

}

angrycata at 2007-7-14 17:21:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Sorry, that was me being stupid..to be a bit clearer

To be a bit clearer

try

{

// connecting to the database

}

catch (Exception exception)

{

out.println("sorry db unavailable");

}

You should ALWAYS put your db connection code in a try catch for reasons you now understand!!

angrycata at 2007-7-14 17:21:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...