Technically neither of those examples would do what you asked in regards to reconnecting for each test. I only meant to provide an example of error handling.
function main()
{
try{
EstablishConnection();
Test1();
//though the connection is properly closed if Test1() fails the entire script ends Test2() is never called
Test2();
}
catch(ex){
Log.Message("ERROR: " + ex.message);
}
finally{
CloseConnection();
}
}
function main()
{
try{
EstablishConnection();
Test1();
}
catch(e){
Log.Message("ERROR: " + e.message);
}
finally{
CloseConnection();
}
/*
there are, of course, numerous ways to handle this, but essentially you want to
reconnect before calling each Test() function
i leave it to you to determine the most elegant method with your current code structure
*/
try{
EstablishConnection();
Test2();
}
catch(e){
Log.Message("ERROR: " + e.message);
}
finally{
CloseConnection();
}
}