File: exception.cpp

package info (click to toggle)
minizinc 2.9.3%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,620 kB
  • sloc: cpp: 74,682; ansic: 8,541; python: 3,322; sh: 79; makefile: 13
file content (60 lines) | stat: -rw-r--r-- 1,556 bytes parent folder | download | duplicates (2)
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
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */

/*
 *  Main authors:
 *     Jason Nguyen <jason.nguyen@monash.edu>
 */

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include <minizinc/exception.hh>
#include <minizinc/prettyprinter.hh>

#include <sstream>

#ifdef _WIN32
#include <Windows.h>
#else
#include <csignal>
#include <unistd.h>
#endif

namespace MiniZinc {
void SignalRaised::raise() const {
#ifdef _WIN32
  GenerateConsoleCtrlEvent(signal(), 0);
#else
  kill(getpid(), signal());
#endif
}

void Exception::print(std::ostream& os) const {
  os << "Error: ";
  if (!std::string(what()).empty()) {
    os << what() << ": ";
  }
  os << _msg << std::endl;
}

void Exception::json(std::ostream& os) const {
  os << "{\"type\": \"error\", \"what\": \"" << Printer::escapeStringLit(std::string(what()))
     << "\", \"message\": \"" << Printer::escapeStringLit(_msg) << "\"}" << std::endl;
}

void InternalError::print(std::ostream& os) const {
  os << "MiniZinc has encountered an internal error. This is a bug." << std::endl
     << "Please file a bug report using the MiniZinc bug tracker." << std::endl
     << "The internal error message was: " << std::endl
     << "\"" << msg() << "\"" << std::endl;
}

void BadOption::print(std::ostream& os) const {
  os << msg() << std::endl;
  if (!_usage.empty()) {
    os << _usage << std::endl;
  }
}

}  // namespace MiniZinc