Replies: 13 comments
-
This is a very nasty piece of generated code. The compiler shouldn't hide any exceptions, unless explicitly told to do so. Error-handling logic is typically maintained by the consumer a resource, not the resource itself. I don't see why transactions, or any other resource, for that matter, should handle exceptions. They have no intrinsic knowledge of the semantic meaning of an exception in the context in which they're being used. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
But the transaction implementation doesn't know that. It only receives an exception instance, without access to its meaning in that given application. BTW, naming wise, I'll call it |
Beta Was this translation helpful? Give feedback.
-
I am not agree with you. We are not talking about .Net BCL transaction. Most framework have it's own transaction implementation and again, a raiser and an using-block handler can be from a single library even from a single operation/workflow. |
Beta Was this translation helpful? Give feedback.
-
IAbortable - good name! Thanks. |
Beta Was this translation helpful? Give feedback.
-
Why not trying to explicitly call |
Beta Was this translation helpful? Give feedback.
-
Simple answer - verbosity. So it is general instrumentation that breaks nothing and allow framework developers to solve problems faster end robust. Following you logic:
|
Beta Was this translation helpful? Give feedback.
-
@dmitriyse Yes,
and this is OK. Calling a Also, |
Beta Was this translation helpful? Give feedback.
-
If you like explicit Commit(), please use it. IAbortable does not restrict you from this logic. Also I agree that in 30% of DB code cases should be implemented with explicit Commit() possibly with try catch logic inside using. There are also cases where explicit Commit() and IAbortable should be used together. This proposal is not for "Best DB practices" but about additional Feature to C# language that will helps to Framework developers to solve very complicated tasks, probably you will never facing with them. |
Beta Was this translation helpful? Give feedback.
-
In general, conceptually is nothing bad that using handler object will kwnow what was happened inside using block. There are tons of code like that someVar.SomeOperation(()=>
{
// Do something that can rise error
}); and SomeOperation analyzes what was happened inside provided Action. for example Unit Tests frameworks can benefits from IAbortable using (assert.Throw<MyException>("Only my exception should be raised"))
{
int a = 0;
Console.WriteLine(123/ a);
} |
Beta Was this translation helpful? Give feedback.
-
Probably this proposal should be merged with #85 |
Beta Was this translation helpful? Give feedback.
-
@dmitriyse Can you please provide something other scenario for proposed feature, that does not related to the database transactions? In which kind of types you want to implement |
Beta Was this translation helpful? Give feedback.
-
After C# 8.0 release, I have revisited |
Beta Was this translation helpful? Give feedback.
-
Most popular scenario is transactions:
Exception detection from using block is very very wanted by millions of developers.
This problem is very old:
http://stackoverflow.com/questions/2830073/detecting-a-dispose-from-an-exception-inside-using-block
Please consider the next improvement to using block pseudo code:
For IAbortable objects wrapped by using block - new behavior should be performed:
when using block is exited due to exception - IAbortable.OnException should be called.
That's all. Simply to implement, powerful, beautiful.
Beta Was this translation helpful? Give feedback.
All reactions