Exceptions

Poluje na pojemnik dający się bezproblemowo używać w programie wielowątkowym. Musi spełniać następujące parametry:

  • template'owy
  • nieblokujące dodawanie, złożoność najwyżej O(logN), najlepiej O(1)
  • nieblokujące kasowanie, złożoność nahwyżej O(n), najlepiej O(1)
  • możliwość iterowania po aktualnym "snapshocie" kolekcji

Czyli coś w rodzaju garbage collector'a z lepszą możliwością iteracji.

Morals About Safe Coding

Cytat:
Moral #4: Always perform unmanaged resource acquisition in the constructor body, never in initializer lists. In other words, either use "resource acquisition is initialization" (thereby avoiding unmanaged resources entirely) or else perform the resource acquisition in the constructor body.

Cytat:
Moral #5: Always clean up unmanaged resource acquisition in local try block handlers within the constructor or destructor body, never in constructor or destructor function try block handlers.

Cytat:
Moral #8: Prefer using "resource acquisition is initialization" to manage resources. Really, really, really. It will save you more headaches than you can probably imagine, including hard-to-see ones, similar to some we've already dissected.

More Exceptional C++, Herb Sutter

 

Below you can find three methods of writing exception safe code in real world. In the order prefered by author:

- Petru's ScopeGuard
- RAII
- try / catch mess
http://www.ddj.com/cpp/184403758

http://msdn.microsoft.com/en-us/library/swezty51(VS.80).aspx

  1. int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep)
  2. {
  3. if (code == EXCEPTION_ACCESS_VIOLATION)
  4. {
  5. return EXCEPTION_EXECUTE_HANDLER;
  6. }
  7. else
  8. {
  9. return EXCEPTION_CONTINUE_SEARCH;
  10. };
  11. }
  12.  
  13. void test()
  14. {
  15. __try
  16. {
  17. *((char *)(NULL)) = 2;
  18. }
  19. __except(filter(GetExceptionCode(), GetExceptionInformation()))
  20. {
  21. cout << "wicked :)";
  22. }
  23. }

_set_se_translator
http://msdn.microsoft.com/en-us/library/5z4bw5h5(VS.80).aspx

/EHa
http://msdn.microsoft.com/en-us/library/1deeycx5(VS.80).aspx

EXCEPTION_ACCESS_VIOLATION
http://msdn.microsoft.com/en-us/library/ms679356(VS.85).aspx

Structured Exception Handling (C++)
http://msdn.microsoft.com/en-us/library/swezty51(VS.80).aspx