File: exception.cpp

package info (click to toggle)
boolector 3.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 20,744 kB
  • sloc: ansic: 83,136; cpp: 18,159; sh: 3,668; python: 2,889; makefile: 210
file content (48 lines) | stat: -rw-r--r-- 859 bytes parent folder | download
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
/**
 * Boolector provides the option to plug in a callback function that is
 * called on abort conditions. This example demonstrates how to use this
 * functionality to extend Boolector's C API with exception handling.
 */

#include "boolector.h"

#include <cstdint>
#include <exception>
#include <iostream>


class Exception : public std::exception
{
 public:
  Exception (const std::string& msg) : msg (msg) {}
  std::string getMsg () { return msg; }

 protected:
  std::string msg;
};

/**
 * The function to be called on abort conditions.
 */
void
abort_fun (const char* msg)
{
  throw Exception (msg);
}

int
main ()
{
  /* Set abort callback function. */
  boolector_set_abort (&abort_fun);

  /* Simple test. */
  try
  {
    boolector_delete (0);
  }
  catch (Exception& e)
  {
    std::cout << "Caught exception: " << e.getMsg () << std::endl;
  }
}