public static bool FillIn()
{
bool success = false;
SqlConnection con = GetConnection();
con.Open();
SqlTransaction tran = con.BeginTransaction();
try
{
if(!Order.New())
{
throw new Exception("Order Create failed!");
}
else if(!nOrder.Update())
{
throw new Excetpion("Norder Update failed!");
}
}
catch
{
tran.Rollback();
}
finally
{
con.close();
}
return success;
}
失败抛出异样合理吗?请高人指点!
{
bool success = false;
SqlConnection con = GetConnection();
con.Open();
SqlTransaction tran = con.BeginTransaction();
try
{
if(!Order.New())
{
throw new Exception("Order Create failed!");
}
else if(!nOrder.Update())
{
throw new Excetpion("Norder Update failed!");
}
}
catch
{
tran.Rollback();
}
finally
{
con.close();
}
return success;
}
失败抛出异样合理吗?请高人指点!
你应该在catch的代码段中也抛出这个异常,向上传播这个异常才有意义。
catch (Exception err )
{
tran.RollBack();
throw err;
}