官术网_书友最值得收藏!

How to do it...

  1. Create a new class called StarShip:
        public class Starship 
{

}
  1. To your class, add a new method that will set the maximum troop capacity of the StarShip class:
        public void SetMaximumTroopCapacity(int capacity) 
{

}
  1. Inside this method, add a trycatch clause that will attempt to set the maximum troop capacity, but for some reason, it will fail. Upon failure, it will write the error to the log table inside the database:
        try 
{
// Read current capacity and try to add more
}
catch (Exception ex)
{
string connectionString = "connection string goes here";
string sql = $"INSERT INTO tblLog (error, date) VALUES
({ex.Message}, GetDate())";
using (SqlConnection con = new
SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand(sql);
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
}
throw ex;
}
主站蜘蛛池模板: 南皮县| 家居| 淮北市| 丹棱县| 台南市| 清流县| 绵竹市| 徐汇区| 舟曲县| 眉山市| 寿光市| 尉犁县| 九龙县| 左权县| 鹤岗市| 漯河市| 信阳市| 开江县| 玉溪市| 长泰县| 阿坝县| 土默特右旗| 长乐市| 甘孜| 威信县| 沁水县| 拉萨市| 龙山县| 贵阳市| 涞源县| 开远市| 军事| 呼伦贝尔市| 博白县| 德保县| 鄂尔多斯市| 灵璧县| 阳江市| 东阿县| 元谋县| 巴中市|