J
John Smith
When implementing exception handling which one of these two alternative
ways of exception-handling is the better one?
******************************************************
Alt1)
******************************************************
try
{
codeline1; //throws exception1, exception2 and exception3
codeline2; //throws exception4, exception5 and exception6
codeline3; //throws exception7, exception8 and exception9
codeline4; //throws exception10, exception11 and exception12
codeline5; //throws exception13, exception14 and exception15
}
catch(exception1){}
catch(exception2){}
catch(exception3){}
...............................
catch(exception14){}
catch(exception15){}
******************************************************
OR Alt 2)
******************************************************
try
{
codeline1; //throws exception1, exception2 and exception3
}
catch(exception1){}
catch(exception2){}
catch(exception3){}
try
{
codeline2; //throws exception4, exception5 and exception6
}
catch(exception4){}
catch(exception5){}
catch(exception6){}
try
{
codeline3; //throws exception7, exception8 and exception9
}
catch(exception4){}
catch(exception5){}
catch(exception6){}
******************************************************
ways of exception-handling is the better one?
******************************************************
Alt1)
******************************************************
try
{
codeline1; //throws exception1, exception2 and exception3
codeline2; //throws exception4, exception5 and exception6
codeline3; //throws exception7, exception8 and exception9
codeline4; //throws exception10, exception11 and exception12
codeline5; //throws exception13, exception14 and exception15
}
catch(exception1){}
catch(exception2){}
catch(exception3){}
...............................
catch(exception14){}
catch(exception15){}
******************************************************
OR Alt 2)
******************************************************
try
{
codeline1; //throws exception1, exception2 and exception3
}
catch(exception1){}
catch(exception2){}
catch(exception3){}
try
{
codeline2; //throws exception4, exception5 and exception6
}
catch(exception4){}
catch(exception5){}
catch(exception6){}
try
{
codeline3; //throws exception7, exception8 and exception9
}
catch(exception4){}
catch(exception5){}
catch(exception6){}
******************************************************