C
Chenxi
Hi,
I have two pieces of sample code which are listed below. I dont understand
two points.
1. why so many exceptions (IOException, JMSException, etc), normally we just
catch Exception. Is there any advantage?
2. what is the difference between finally and no finally? see the code.
connection.close() will be invoked. why use finally?
Thank you.
Chenxi
=====
try{
// initialising code
connection = ...
...
}catch(IOException e){
...
}catch(JMSException e){
...
}finally{
if (connection!=null)
connection.close();
}
=======
try{
// initialising code
connection = ...
...
}catch(Exception e){
...
}
if (connection!=null)
connection.close();
I have two pieces of sample code which are listed below. I dont understand
two points.
1. why so many exceptions (IOException, JMSException, etc), normally we just
catch Exception. Is there any advantage?
2. what is the difference between finally and no finally? see the code.
connection.close() will be invoked. why use finally?
Thank you.
Chenxi
=====
try{
// initialising code
connection = ...
...
}catch(IOException e){
...
}catch(JMSException e){
...
}finally{
if (connection!=null)
connection.close();
}
=======
try{
// initialising code
connection = ...
...
}catch(Exception e){
...
}
if (connection!=null)
connection.close();