Path: blob/main/contrib/kyua/utils/fs/exceptions.cpp
48081 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/fs/exceptions.hpp"2930#include <cstring>3132#include "utils/format/macros.hpp"3334namespace fs = utils::fs;353637/// Constructs a new error with a plain-text message.38///39/// \param message The plain-text error message.40fs::error::error(const std::string& message) :41std::runtime_error(message)42{43}444546/// Destructor for the error.47fs::error::~error(void) throw()48{49}505152/// Constructs a new invalid_path_error.53///54/// \param textual_path Textual representation of the invalid path.55/// \param reason Description of the error in the path.56fs::invalid_path_error::invalid_path_error(const std::string& textual_path,57const std::string& reason) :58error(F("Invalid path '%s': %s") % textual_path % reason),59_textual_path(textual_path)60{61}626364/// Destructor for the error.65fs::invalid_path_error::~invalid_path_error(void) throw()66{67}686970/// Returns the invalid path related to the exception.71///72/// \return The textual representation of the invalid path.73const std::string&74fs::invalid_path_error::invalid_path(void) const75{76return _textual_path;77}787980/// Constructs a new join_error.81///82/// \param textual_path1_ Textual representation of the first path.83/// \param textual_path2_ Textual representation of the second path.84/// \param reason Description of the error in the join operation.85fs::join_error::join_error(const std::string& textual_path1_,86const std::string& textual_path2_,87const std::string& reason) :88error(F("Cannot join paths '%s' and '%s': %s") % textual_path1_ %89textual_path2_ % reason),90_textual_path1(textual_path1_),91_textual_path2(textual_path2_)92{93}949596/// Destructor for the error.97fs::join_error::~join_error(void) throw()98{99}100101102/// Gets the first path that caused the error in a join operation.103///104/// \return The textual representation of the path.105const std::string&106fs::join_error::textual_path1(void) const107{108return _textual_path1;109}110111112/// Gets the second path that caused the error in a join operation.113///114/// \return The textual representation of the path.115const std::string&116fs::join_error::textual_path2(void) const117{118return _textual_path2;119}120121122/// Constructs a new error based on an errno code.123///124/// \param message_ The message describing what caused the error.125/// \param errno_ The error code.126fs::system_error::system_error(const std::string& message_, const int errno_) :127error(F("%s: %s") % message_ % std::strerror(errno_)),128_original_errno(errno_)129{130}131132133/// Destructor for the error.134fs::system_error::~system_error(void) throw()135{136}137138139140/// \return The original errno code.141int142fs::system_error::original_errno(void) const throw()143{144return _original_errno;145}146147148/// Constructs a new error with a plain-text message.149///150/// \param message The plain-text error message.151fs::unsupported_operation_error::unsupported_operation_error(152const std::string& message) :153error(message)154{155}156157158/// Destructor for the error.159fs::unsupported_operation_error::~unsupported_operation_error(void) throw()160{161}162163164