What are industry standard best practices for implementing custom exceptions in C#? -
what industry standard best practices implementing custom exceptions in c#?
i have checked google , there's great number of recommendations, don't know ones hold more credibility.
if has links authoritative articles, helpful.
the standard creating custom exceptions derive exception. can introduce own properties/methods , overloaded constructors (if applicable).
here basic example of custom connectionfailedexception
takes in parameter specific type of exception.
[serializable] public class connectionfailedexception : exception { public connectionfailedexception(string message, string connectionstring) : base(message) { connectionstring = connectionstring; } public string connectionstring { get; private set; } }
in application used in scenarios application attempting connect database e.g.
try { connecttodb(aconnstring); } catch (exception ex) { throw new connectionfailedexception(ex.message, aconnstring); }
it's handle connectionfailedexception
@ higher level (if applicable)
also have @ designing custom exceptions , custom exceptions
Comments
Post a Comment