File: TestThrow.cpp

package info (click to toggle)
scipy 1.16.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 236,092 kB
  • sloc: cpp: 503,720; python: 345,302; ansic: 195,677; javascript: 89,566; fortran: 56,210; cs: 3,081; f90: 1,150; sh: 857; makefile: 792; pascal: 284; csh: 135; lisp: 134; xml: 56; perl: 51
file content (83 lines) | stat: -rw-r--r-- 1,899 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// #include "Highs.h"
#include <iostream>
#include <stdexcept>  //Used in HiGHS

#include "HCheckConfig.h"
#include "catch.hpp"
// #include <exception>
const bool dev_run = false;

void invalidArgument() {
  // Used in .lp file reader
  throw std::invalid_argument("Exception: invalid_argument");
}

void logicError() {
  // Used in IPX
  throw std::logic_error("Exception: logic_error");
}

void badAlloc() {
  // Used in IPX
  throw std::bad_alloc();
}

TEST_CASE("ThrowCatch", "[highs_test_throw]") {
  bool ok;
  // Check that all exceptions usind in HiGHS are caught
  //
  // Catch invalid_argument explicitly
  ok = false;
  try {
    invalidArgument();
  } catch (const std::invalid_argument& exception) {
    if (dev_run) std::cout << exception.what() << std::endl;
    ok = true;
  }
  REQUIRE(ok);
  // Catch logic_error explicitly
  ok = false;
  try {
    logicError();
  } catch (const std::logic_error& exception) {
    if (dev_run) std::cout << exception.what() << std::endl;
    ok = true;
  }
  REQUIRE(ok);
  // Catch bad_alloc explicitly
  ok = false;
  try {
    badAlloc();
  } catch (const std::bad_alloc& exception) {
    if (dev_run) std::cout << exception.what() << std::endl;
    ok = true;
  }
  REQUIRE(ok);
  // Catch invalid_argument via exception
  ok = false;
  try {
    invalidArgument();
  } catch (const std::exception& exception) {
    if (dev_run) std::cout << exception.what() << std::endl;
    ok = true;
  }
  REQUIRE(ok);
  // Catch logic_error via exception
  ok = false;
  try {
    logicError();
  } catch (const std::exception& exception) {
    if (dev_run) std::cout << exception.what() << std::endl;
    ok = true;
  }
  REQUIRE(ok);
  // Catch bad_alloc via exception
  ok = false;
  try {
    badAlloc();
  } catch (const std::exception& exception) {
    if (dev_run) std::cout << exception.what() << std::endl;
    ok = true;
  }
  REQUIRE(ok);
}