ipaddress 1.1.0
Loading...
Searching...
No Matches
errors.hpp File Reference

Declares error codes and exceptions for IP address operations. More...

#include "config.hpp"

Go to the source code of this file.

Classes

class  error
 The primary exception class used by the IP address library. More...
 
class  parse_error
 Exception for errors encountered during IP address parsing. More...
 
class  logic_error
 Exception for logical errors in IP address operations. More...
 

Namespaces

namespace  ipaddress
 Namespace dedicated to IP addresses and networks operations.
 

Enumerations

enum class  error_code {
  no_error = 0 ,
  empty_address ,
  empty_netmask ,
  invalid_netmask ,
  netmask_pattern_mixes_zeroes_and_ones ,
  has_host_bits_set ,
  only_one_slash_permitted ,
  string_is_too_long ,
  empty_octet ,
  expected_4_octets ,
  leading_0_are_not_permitted ,
  octet_more_3_characters ,
  octet_has_invalid_symbol ,
  octet_exceeded_255 ,
  least_3_parts ,
  most_8_colons_permitted ,
  part_is_more_4_chars ,
  part_has_invalid_symbol ,
  most_one_double_colon_permitted ,
  leading_colon_only_permitted_as_part_of_double_colon ,
  trailing_colon_only_permitted_as_part_of_double_colon ,
  expected_at_most_7_other_parts_with_double_colon ,
  exactly_8_parts_expected_without_double_colon ,
  scope_id_is_too_long ,
  invalid_scope_id ,
  invalid_version ,
  invalid_prefixlen_diff ,
  new_prefix_must_be_shorter ,
  new_prefix_must_be_longer ,
  cannot_set_prefixlen_diff_and_new_prefix ,
  not_contained_network ,
  unexpected_symbol ,
  wrong_encoding_sequence
}
 Enumeration of error codes for IP address parsing and validation. More...
 

Functions

template<typename T >
constexpr inline void raise_error (error_code code, uint32_t value, const T *address, size_t length)
 Raises an error with a specific error code and additional context.
 

Detailed Description

Declares error codes and exceptions for IP address operations.

Author
Vladimir Shaleev

This header file is part of an IP address processing library and is responsible for defining error codes and exceptions that represent various failure states encountered during IP address parsing and processing. It includes an enumeration of error codes that cover a range of issues from syntactical errors in IP address strings to logical inconsistencies in network operations. Additionally, the file declares a base exception class tailored to encapsulate these error codes along with descriptive messages, facilitating precise error handling and reporting.

The error codes are categorized into general parsing errors, IPv4-specific errors, IPv6-specific errors, and logical errors, each with a brief description of the condition they represent. The base exception class, error, inherits from the standard std::runtime_error and is constructed with an error code and a message, allowing exceptions to carry both a machine-readable identifier and a human-readable explanation.

The file also includes a function template that converts an error code into an exception, streamlining the process of throwing exceptions upon encountering errors during IP address operations. This design ensures that all potential error conditions are accounted for and can be handled gracefully by client code using the library.