libcruft-util/json/schema/except.hpp

65 lines
1.6 KiB
C++
Raw Normal View History

/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
*/
#pragma once
#include "fwd.hpp"
#include "introspection.hpp"
#include "../fwd.hpp"
#include <exception>
///////////////////////////////////////////////////////////////////////////////
namespace util::json::schema {
class error : public std::exception { };
template <typename T>
class constraint_error : public error {
public:
virtual ~constraint_error () = default;
constraint_error (::json::tree::node const &_def):
def (_def)
{ ; }
char const* what (void) const noexcept override
{
return util::type_name_v<T>;
}
::json::tree::node const &def;
};
class unknown_constraint : public error {
public:
unknown_constraint (std::string const &name):
m_name (name)
{ ; }
virtual ~unknown_constraint () = default;
char const* what (void) const noexcept override
{
return m_name.c_str ();
}
private:
std::string m_name;
};
}