When talking about SOLID principles, we will start off with the SRP. Here, we are actually saying that a class has a specific task that it needs to fulfil and it should not do anything else.
You will create a new class and write code to log an error to the database when an exception is thrown on adding more troops to the star ship, causing it to be over capacity.
Create a new class called
StarShip
:public class Starship { }
To your class, add a new method that will set the maximum troop capacity of the
StarShip
class:public void SetMaximumTroopCapacity(int capacity) { }
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...