2 * Copyright 2015 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <folly/Conv.h>
23 #include <folly/detail/IPAddress.h>
28 * Exception for invalid IP addresses.
30 class IPAddressFormatException : public std::exception {
32 explicit IPAddressFormatException(const std::string& msg)
34 IPAddressFormatException(
35 const IPAddressFormatException&) = default;
36 template<typename... Args>
37 explicit IPAddressFormatException(Args&&... args)
38 : msg_(to<std::string>(std::forward<Args>(args)...)) {}
40 virtual ~IPAddressFormatException() noexcept {}
41 virtual const char *what(void) const noexcept {
46 const std::string msg_;
49 class InvalidAddressFamilyException : public IPAddressFormatException {
51 explicit InvalidAddressFamilyException(const std::string& msg)
52 : IPAddressFormatException(msg) {}
53 InvalidAddressFamilyException(
54 const InvalidAddressFamilyException&) = default;
55 explicit InvalidAddressFamilyException(sa_family_t family)
56 : IPAddressFormatException("Address family " +
57 detail::familyNameStr(family) +
58 " is not AF_INET or AF_INET6") {}
59 template<typename... Args>
60 explicit InvalidAddressFamilyException(Args&&... args)
61 : IPAddressFormatException(std::forward<Args>(args)...) {}