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;
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.237.29