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 ...

Get C# 7 and .NET Core Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.