Can following code be considered as a good practice? If not, why?
try
{
// code that can cause various exceptions.
You can use ellipses too.
catch (...)
{
// catches all exceptions, not already catches by a catch block before
// can be used to catch exception of unknown or irrelevant type
}
Except this what you can do is nested try-catch
try
{
//some code which is not for database related
try
{
//database related code with connection open
}
catch(//database related exception)
{
//statement to terminate
}
**finally()
{
//close connection,destroy object
}**
}
catch(//general exception)
{
//statement to terminate
}
According to me, this would help you to get more concise idea of your error type.