Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into disk
[simgrid.git] / src / simgrid / Exception.cpp
1 /* Copyright (c) 2018-2019. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include <simgrid/Exception.hpp>
7
8 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
9
10 namespace simgrid {
11
12 // DO NOT define destructors for exceptions in Exception.hpp.
13 // Defining it here ensures that the exceptions are defined only in libsimgrid, but not in libsimgrid-java.
14 // Doing otherwise naturally breaks things (at least on freebsd with clang).
15
16 Exception::~Exception()                         = default;
17 ForcefulKillException::~ForcefulKillException() = default;
18
19 void ForcefulKillException::do_throw()
20 {
21   throw ForcefulKillException();
22 }
23
24 bool ForcefulKillException::try_n_catch(const std::function<void()>& try_block)
25 {
26   bool res;
27   try {
28     try_block();
29     res = true;
30   } catch (ForcefulKillException const&) {
31     XBT_DEBUG("Caught a ForcefulKillException");
32     res = false;
33   }
34   return res;
35 }
36 } // namespace simgrid