using System.Collections.Generic;
public static void Main()
Console.WriteLine("Hello World");
throw ExceptionHelper.CreateTechnicalException(1001);
catch (TechnicalException ex)when (ex.ErrorSeverity > Severity.Warning)
Console.WriteLine($"{ex.ErrorCode} {ex.Message}");
throw ExceptionHelper.CreateTechnicalException(2002);
catch (TechnicalException ex)when (ex.ErrorSeverity > Severity.Warning)
Console.WriteLine($"{ex.ErrorCode} {ex.Message.Replace("$id$", "1").Replace("$type$", "myType")}");
public static class ExceptionHelper
private static Dictionary<int, string> TechnicalErrorDictionary = new Dictionary<int, string>{{1001, "User with id $id$ does not exist"}, {1002, "Created user with id $id$"}, {2002, "User with id $id$ with type $type$ is invalid"}, {3003, "Unexpected server error"}, {4001, "Some text with $param1$ and another $param2$ included on $param3$"}};
public static TechnicalException CreateTechnicalException(int errorCode)
return new TechnicalException(errorCode, TechnicalErrorDictionary[errorCode]);
public class TechnicalException : Exception
public Severity ErrorSeverity
public TechnicalException(int errorCode, string errorDescription): base (errorDescription)
ErrorSeverity = Severity.Error;