diff --git a/HW02LAZY/LAZY/Lazy.cs b/HW02LAZY/LAZY/Lazy.cs index f8b4244..e027e91 100644 --- a/HW02LAZY/LAZY/Lazy.cs +++ b/HW02LAZY/LAZY/Lazy.cs @@ -34,7 +34,14 @@ public LazySingleThread(Func supplier) public T? Get() { if (!_isCalculated) { - _result = _supplier(); + try + { + _result = _supplier(); + } + catch + { + _result = default(T); + } } _isCalculated = true; return _result; @@ -76,8 +83,17 @@ public LazyMultiThread(Func supplier) { if (Volatile.Read(ref _isCalculated)) return _result; - _result = _supplier(); - Volatile.Write(ref _isCalculated, true); + + try + { + _result = _supplier(); + Volatile.Write(ref _isCalculated, true); + } + catch + { + _result = default(T); + } + return _result; } }