Path: blob/main/contrib/kyua/utils/format/exceptions.cpp
48178 views
// Copyright 2010 The Kyua Authors.1// All rights reserved.2//3// Redistribution and use in source and binary forms, with or without4// modification, are permitted provided that the following conditions are5// met:6//7// * Redistributions of source code must retain the above copyright8// notice, this list of conditions and the following disclaimer.9// * Redistributions in binary form must reproduce the above copyright10// notice, this list of conditions and the following disclaimer in the11// documentation and/or other materials provided with the distribution.12// * Neither the name of Google Inc. nor the names of its contributors13// may be used to endorse or promote products derived from this software14// without specific prior written permission.15//16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2728#include "utils/format/exceptions.hpp"2930using utils::format::bad_format_error;31using utils::format::error;32using utils::format::extra_args_error;333435/// Constructs a new error with a plain-text message.36///37/// \param message The plain-text error message.38error::error(const std::string& message) :39std::runtime_error(message)40{41}424344/// Destructor for the error.45error::~error(void) throw()46{47}484950/// Constructs a new bad_format_error.51///52/// \param format_ The invalid format string.53/// \param message Description of the error in the format string.54bad_format_error::bad_format_error(const std::string& format_,55const std::string& message) :56error("Invalid formatting string '" + format_ + "': " + message),57_format(format_)58{59}606162/// Destructor for the error.63bad_format_error::~bad_format_error(void) throw()64{65}666768/// \return The format string that caused the error.69const std::string&70bad_format_error::format(void) const71{72return _format;73}747576/// Constructs a new extra_args_error.77///78/// \param format_ The format string.79/// \param arg_ The first extra argument passed to the format string.80extra_args_error::extra_args_error(const std::string& format_,81const std::string& arg_) :82error("Not enough fields in formatting string '" + format_ + "' to place "83"argument '" + arg_ + "'"),84_format(format_),85_arg(arg_)86{87}888990/// Destructor for the error.91extra_args_error::~extra_args_error(void) throw()92{93}949596/// \return The format string that was passed too many arguments.97const std::string&98extra_args_error::format(void) const99{100return _format;101}102103104/// \return The first argument that caused the error.105const std::string&106extra_args_error::arg(void) const107{108return _arg;109}110111112