Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // in folder Exceptions write your Exceptions messages
- namespace Vehicles.Exceptions
- {
- public static class ExceptionMessages
- {
- public const string NotEnoughFuelMessage = "{0} needs refueling"; // without $
- public const string InvalidVehicleTypeMessage = "Type is not valid";
- }
- }
- // in folder Models or in folder Factory you throw the exception
- // string exceptionMessage = String.Format(ExceptionMessages.NotEnoughFuelMessage, this.GetType().Name);
- // throw new InvalidOperationException(exceptionMessage);
- // or throw new ArgumentException(String.Format(ExceptionMessages.InvalidVehicleTypeMessage));
- // in Engine you catch the exception
- try
- {
- }
- catch (InvalidOperationException ex)
- {
- Console.WriteLine(ex.Message); // "The Fuel is not enough" - only this one
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement