Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Exceptions.cpp 1.8KB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Carla Exception Tests
  3. * Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "CarlaDefines.h"
  18. #include "CarlaJuceUtils.hpp"
  19. // -----------------------------------------------------------------------
  20. struct Struct1 {
  21. Struct1() noexcept : leakDetector_Struct1() {}
  22. ~Struct1() noexcept {}
  23. void throwHere()
  24. {
  25. throw 1;
  26. }
  27. CARLA_LEAK_DETECTOR(Struct1)
  28. };
  29. struct Struct2 {
  30. Struct2() : leakDetector_Struct2() { throw 2; }
  31. ~Struct2() noexcept {}
  32. CARLA_LEAK_DETECTOR(Struct2)
  33. };
  34. // -----------------------------------------------------------------------
  35. int main()
  36. {
  37. carla_safe_assert("test here", __FILE__, __LINE__);
  38. Struct1 a1;
  39. Struct1* b1;
  40. Struct2* c2 = nullptr;
  41. try {
  42. a1.throwHere();
  43. } CARLA_SAFE_EXCEPTION("Struct1 a throw");
  44. try {
  45. b1 = new Struct1;
  46. } CARLA_SAFE_EXCEPTION("NOT POSSIBLE! Struct1 b throw constructor");
  47. assert(b1 != nullptr);
  48. try {
  49. b1->throwHere();
  50. } CARLA_SAFE_EXCEPTION("Struct1 b throw runtime");
  51. delete b1;
  52. b1 = nullptr;
  53. try {
  54. c2 = new Struct2;
  55. } CARLA_SAFE_EXCEPTION("Struct2 c throw");
  56. assert(c2 == nullptr);
  57. return 0;
  58. }
  59. // -----------------------------------------------------------------------