Catching Sql Exception In Entity Framework4?What is the best practice? -
what practices use in datalayer catch sql exceptions? has written generic sql exception handler catch common errors ?
how do examples out there?
thanks
handle unexpected exception underlying layer only
exceptions data layer (in case entity framework) should handled business layer. business layer can raise (if necessary) more high-level exception presentation layer (ui).
don't throw , catch exceptions across more 1 layer of application. considered bad practice. presentation layer should handle business layer exceptions.
never swallow exceptions using:
try {} catch (exception) { // cares }
catch expected exceptions possible
always try handle expected exceptions (e.g. filenotfoundexception
) possible. if can handle it, handle directly there. if not, re-throw custom exception , handle in underlying layer.
don't clear stack trace when re-throwing exception
catch , re-throw implicitly (see)
try {} catch (exception) { throw; }
and not explicitly
try {} catch (exception ex) { throw ex; }
Comments
Post a Comment