Skip to content

Commit 2aa42c4

Browse files
committed
remove error handler
1 parent 6767b3b commit 2aa42c4

File tree

3 files changed

+3
-69
lines changed

3 files changed

+3
-69
lines changed

src/pcms/assert.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,6 @@
44
#include <cstdlib>
55
namespace pcms
66
{
7-
8-
namespace
9-
{
10-
error_mode current_mode = error_mode::throw_exception;
11-
}
12-
13-
void set_error_mode(error_mode mode)
14-
{
15-
current_mode = mode;
16-
}
17-
18-
void handle_error(const exception& e)
19-
{
20-
switch (current_mode) {
21-
case error_mode::throw_exception: throw e;
22-
23-
case error_mode::abort: std::abort();
24-
25-
case error_mode::return_code:
26-
default: break;
27-
}
28-
}
29-
30-
void handle_mpi_error(const pcms::exception& e)
31-
{
32-
int local_fatal = (e.level() == pcms::error_level::fatal);
33-
int global_fatal = 0;
34-
35-
MPI_Allreduce(&local_fatal, &global_fatal, 1, MPI_INT, MPI_MAX,
36-
MPI_COMM_WORLD);
37-
38-
switch (current_mode) {
39-
case pcms::error_mode::throw_exception: throw e;
40-
41-
case pcms::error_mode::abort:
42-
if (global_fatal)
43-
MPI_Abort(MPI_COMM_WORLD, e.code());
44-
break;
45-
46-
case pcms::error_mode::return_code:
47-
default: break;
48-
}
49-
}
50-
517
void Pcms_Assert_Fail(const char* msg)
528
{
539
printError("%s", msg);

src/pcms/assert.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,12 @@
4747

4848
namespace pcms
4949
{
50-
enum class error_level
51-
{
52-
recoverable, // safe to continue
53-
resource_leak, // may cause resource leaks
54-
fatal // undefined or broken state
55-
};
56-
57-
enum class error_mode
58-
{
59-
return_code,
60-
throw_exception,
61-
abort
62-
};
6350

6451
class exception : public std::exception
6552
{
6653
public:
67-
exception(std::string message, int error_code = 0,
68-
error_level level = error_level::fatal, std::string specific = {})
69-
: error_code_(error_code), level_(level)
54+
exception(std::string message, int error_code = 0, std::string specific = {})
55+
: error_code_(error_code)
7056
{
7157
std::ostringstream oss;
7258
oss << message;
@@ -80,18 +66,12 @@ class exception : public std::exception
8066
const char* what() const noexcept override { return error_message_.c_str(); }
8167

8268
int code() const noexcept { return error_code_; }
83-
error_level level() const noexcept { return level_; }
8469

8570
private:
8671
std::string error_message_;
8772
int error_code_;
88-
error_level level_;
8973
};
9074

91-
void set_error_mode(error_mode mode);
92-
void handle_error(const exception& e);
93-
void handle_mpi_error(const exception& e);
94-
9575
// from scorec/core/pcu_fail.h
9676
void Pcms_Assert_Fail(const char* msg) __attribute__((noreturn));
9777
} // namespace pcms

test/test_error_handling.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
int raise_error(int code)
77
{
88
if (code) {
9-
pcms::handle_error(pcms::exception("Mesh validation failed", 1,
10-
pcms::error_level::recoverable));
11-
9+
throw pcms::exception("Test exception", code, "Raising error for testing");
1210
return 1;
1311
}
1412
return 0;

0 commit comments

Comments
 (0)