c# - How to return an exception thrown in one project to another? -
is there way catch , return exception thrown 1 project another?
for example, i'm keeping codes in different projects . , b. if engine part , b ui part, exception occurred in engine should caught in ui well.please help.
if want catch exceptions @ ui level can not catch them @ engine level.
for running application there no difference in assembly (every project creates assembly) exception thrown.
if have catch , re-throw exception @ engine level re-throw correctly
catch(exception ex) { // whatever logic throw; }
or wrap it
catch(exception ex) { // whatever logic throw new yourengineexception("some message", ex); }
if want log it, don't it, if not cross process boundaries.
catch, log, re-throw anti pattern in opinion. creates bazillion log entries, catching @ highest possible level should enough if don't destroy stack trace.
use wrapping if can provide extra information exception. example if have 1 method loads data, changes , saves wrap exception , add "error '{0}' when saving" or else. don't forget include originating exception inner exception.
Comments
Post a Comment