PLaSK library

Loading...
Searching...
No Matches
exceptions.cpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#include "exceptions.hpp"
15#include "reader.hpp"
16
17 namespace plask {
18
19 XMLException::XMLException(const XMLReader& reader, const std::string& msg):
20 std::runtime_error("XML line " + boost::lexical_cast<std::string>(reader.getLineNr()) +
21 ((reader.getNodeType() == XMLReader::NODE_ELEMENT)? " in <" + reader.getNodeName() + ">" :
22 (reader.getNodeType() == XMLReader::NODE_ELEMENT_END)? " in </" + reader.getNodeName() + ">" :
23 "") +
24 ": " + msg), line(reader.getLineNr()) {}
25
26 XMLException::XMLException(const std::string& where, const std::string& msg, int line):
27 std::runtime_error(where + ": " + msg), line(line) {}
28
29 XMLException::XMLException(const std::string& msg, int line): std::runtime_error(msg), line(line) {}
30
31 XMLUnexpectedElementException::XMLUnexpectedElementException(const XMLReader& reader, const std::string& what_is_expected):
32 XMLException(reader, "expected " + what_is_expected + ", got " + (
33 reader.getNodeType() == XMLReader::NODE_ELEMENT ? ("<"+reader.getNodeName()+">") :
34 reader.getNodeType() == XMLReader::NODE_ELEMENT_END ? ("</"+reader.getNodeName()+">") :
35 "text"
36 ) + " instead") {}
37
38
39} // namespace plask