StreamReader reader=new  StreamReader("myfile.txt");
try
{
 
int i = 5 / 0;
}
catch   // No args, so it will catch any exception
{}
reader.Close();
StreamReader reader=new  StreamReader("myfile.txt");
try
{
 
int i = 5 / 0;
}
finally   // Will execute despite any exception
{
  reader.Close();
}
The big difference is that try...catch will swallow the exception, hiding the fact that an error occurred. try..finally will run your cleanup code and then the exception will keep going, to be handled by something that knows what to do with it.
posted on 2011-06-17 18:03  tonylx  阅读(119)  评论(0)    收藏  举报