Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 14th, 2012  |  syntax: None  |  size: 0.83 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Lazy<T> breaks when exception is handled
  2. Lazy<int> lazyCount = new Lazy<int>(() => { throw new NotImplementedException(); }, System.Threading.LazyThreadSafetyMode.None);
  3. Func<int> valueGenerator = () => { throw new NotImplementedException(); };
  4.  
  5. try
  6. {
  7.     int value = lazyCount.Value;
  8. }
  9. catch (NotImplementedException e)
  10. {
  11.     Console.WriteLine("Breaks");
  12. }
  13.  
  14. try
  15. {
  16.     int value = valueGenerator();
  17. }
  18. catch (NotImplementedException e)
  19. {
  20.     Console.WriteLine("Doesn't Breaks");
  21. }
  22.  
  23. try
  24. {
  25.     throw new NotImplementedException();
  26. }
  27. catch (NotImplementedException e)
  28. {
  29.     Console.WriteLine("Doesn't break");
  30. }
  31. Console.ReadLine();
  32.        
  33. Func<int> a = () => { throw new NotImplementedException(); };
  34.  
  35.         try
  36.         {
  37.             //int value = lazyCount.Value;
  38.             a();
  39.         }
  40.         catch (NotImplementedException e)
  41.         {
  42.         }