Entity framework exceptions -
i'm having thought on mind quite time , still can not find answer. dbcontext handled unitofwork class. have 1 place savechanges occur , catching of nasty exceptions , handling them in 1 place.
but, known, dbcontext can throw other types of exceptions in places besides in savechanges() method. example when materializing entities. can happen in many places , overhead write try catch blocks on every firstordefault() or tolist() call , catching , re throwing exceptions. exceptions can of sql type meaning connection cannot open, entitycommandexecutionexception or others.
so wondering there event dbcontext object fires when exception occurs, can subscribe event , handle logic in these scenarios. :)
no, there isn't. , never be, (at least) 3 reasons:
exceptions may thrown intentionally, can occur somewhere in ef's source code , bubble up. in former case could fire event, in latter case not. you'll never safe.
how should event fired? there several ways throw event. 1 of them re-throw in catch block. firing
event
in catch block sounds very bad practice. catch blocks should contain safe, stable code. if exception occurs in catch block things go bad worse. give me bad feeling if hook kind of code in catch blocks.when should event fired? exceptions may thrown and handled within ef assembly. never want know occurred. in scenario same exception may bubble up.
Comments
Post a Comment