overuse

Exceptions: When to use, timing, overall use

匆匆过客 提交于 2019-12-18 07:18:50
问题 I'll try and ask my question so it doesn't end as a simple argumentative thread. I've jumped into an application coded in C# recently and I'm discovering the exception mechanism. And I've had a few bad experiences with them such as the following // _sValue is a string try { return float.Parse(_sValue); } catch { return 0; } I changed it into : float l_fParsedValue = 0.0f; if (float.TryParse(_sValue, out l_fParsedValue)) { return l_fParsedValue; } else { return 0; } Result, my Output in Visual

Observer pattern - when to

跟風遠走 提交于 2019-12-10 14:58:49
问题 We have been arguing back and forth at my work place about the use of the Observer pattern for one of the problems. I somehow smell "overuse" but am open to ideas. So the requirement is We have a hierarchy of objects -> an order and multiple line items in the order. When the order is cancelled, all the line items need to cancelled. To do this, we have created a OrderCancel class which is the Subject in the Observer pattern idiom and LineItemCancel class which is the Observer. We also have a

Exceptions: When to use, timing, overall use

一世执手 提交于 2019-11-29 12:31:00
I'll try and ask my question so it doesn't end as a simple argumentative thread. I've jumped into an application coded in C# recently and I'm discovering the exception mechanism. And I've had a few bad experiences with them such as the following // _sValue is a string try { return float.Parse(_sValue); } catch { return 0; } I changed it into : float l_fParsedValue = 0.0f; if (float.TryParse(_sValue, out l_fParsedValue)) { return l_fParsedValue; } else { return 0; } Result, my Output in Visual Studio is not anymore flooded with message like First chance System.FormatException blabla when string