throw_errno_override.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include<__vic/throw_errno.h>
  2. #include<__vic/error.h>
  3. #include<iostream>
  4. #include<exception>
  5. #include<cstring>
  6. #include<cassert>
  7. //////////////////////////////////////////////////////////////////////////////
  8. struct my_exception : public __vic::exception
  9. {
  10. explicit my_exception(const char *msg) : __vic::exception(msg) {}
  11. };
  12. //////////////////////////////////////////////////////////////////////////////
  13. //----------------------------------------------------------------------------
  14. // Override library functions to throw my_exception
  15. //----------------------------------------------------------------------------
  16. void __vic::throw_errno(const char *prompt, int err_no)
  17. {
  18. throw my_exception(prompt);
  19. }
  20. //----------------------------------------------------------------------------
  21. void run_tests()
  22. {
  23. try
  24. {
  25. __vic::throw_errno("test");
  26. assert(false);
  27. }
  28. catch(const my_exception & )
  29. {
  30. // OK
  31. }
  32. catch(...)
  33. {
  34. assert(false);
  35. }
  36. }
  37. int main()
  38. {
  39. try
  40. {
  41. run_tests();
  42. return 0;
  43. }
  44. catch(const std::exception &ex)
  45. {
  46. std::cerr << ex.what() << '\n';
  47. }
  48. return 1;
  49. }