xtd 0.2.0
Loading...
Searching...
No Matches
xtd::format_exception Class Reference
Inheritance diagram for xtd::format_exception:
xtd::system_exception xtd::exception xtd::object xtd::io::file_format_exception xtd::net::cookie_exception xtd::uri_format_exception

Definition

The exception that is thrown when the format of an argument does not meet the parameter specifications of the invoked method.

Namespace
xtd
Library
xtd.core
Examples
The following example demonstrates how to throw and catch an format_exception.
#include <xtd/environment>
#include <xtd/format>
#include <xtd/println>
using namespace xtd;
class character : public iformatable {
public:
character() = default;
character(const string& name, const string& rank) noexcept : name_(name), rank_(rank) {}
const string& name() const noexcept {return name_;}
const string& rank() const noexcept {return rank_;}
string to_string() const noexcept {return to_string("", std::locale {});}
string to_string(const string& format, const std::locale& loc) const override {
auto fmt = string::is_empty(format) ? "F" : format;
if (fmt == "F") return name_ + " (" + rank_ + ")";
if (fmt == "N") return name_;
if (fmt == "R") return rank_;
throw format_exception {xtd::format("The \"{}\" value is not valid format.", fmt)};
}
private:
string name_;
string rank_;
};
auto main() -> int {
try {
auto char1 = character {"Jean-Luc Picard", "Captain"};
println("1 : {}", char1);
println("2 : {:N}", char1);
println("2 : {:B}", char1);
} catch (const exception& e) {
}
}
// This code can produce the following output :
//
// 1 : Jean-Luc Picard (Captain)
// 2 : Jean-Luc Picard
// xtd::format_exception : The "B" value is not valid format.
// at character::to_string(xtd::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::locale const&) const in /Users/gammasoft/Projects/xtd/examples/xtd.core.examples/format/format_exception/src/format_exception.cpp:line 22
// at xtd::iformatable::__opague_internal_formatable__(long, long, long, long) const in iformatable.cpp:line 7
// at void __basic_string_extract_format_arg<character&>(std::basic_string<char, std::char_traits<char>, std::allocator<char>>&, unsigned long&, std::vector<__format_information<char>, std::allocator<__format_information<char>>>&, character&) in basic_string_.hpp:line 365
// at void __basic_string_extract_format_arg<character&>(xtd::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::vector<__format_information<char>, std::allocator<__format_information<char>>>&, character&) in basic_string_.hpp:line 387
// at xtd::basic_string<char, std::char_traits<char>, std::allocator<char>> xtd::basic_string<char, std::char_traits<char>, std::allocator<char>>::format<character&>(xtd::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, character&) in basic_string_.hpp:line 328
// at void xtd::println<character&>(char const*, character&) in println.hpp:line 34
// at main in format_exception.cpp:line 34
Defines the base class for predefined exceptions in the xtd namespace.
Definition exception.hpp:28
The exception that is thrown when the format of an argument does not meet the parameter specification...
Definition format_exception.hpp:19
Provides functionality to format the value of an object into a string representation.
Definition iformatable.hpp:35
xtd::string format(const xtd::string &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition format.hpp:20
@ character
Specifies that the text is trimmed to the nearest character.
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition to_string.hpp:41
@ e
The E key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
void println()
Writes the current line terminator to the standard output stream using the specified format informati...
Definition println.hpp:10
Examples
format_class_with_specified_formating.cpp, format_class_with_specified_formating_with_to_string.cpp, format_exception.cpp, iformatable_vs_to_string.cpp, sprintf_class_with_specified_formating.cpp, and sprintf_class_with_specified_formating_with_to_string.cpp.

Public Constructors

 format_exception (const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class format_exception.
 
 format_exception (const std::optional< xtd::string > &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class format_exception.
 
template<typename exception_t >
 format_exception (const std::optional< xtd::string > &message, const exception_t &inner_exception, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class format_exception.
 
 format_exception (const xtd::string &message, const std::error_code &error, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class format_exception.
 
 format_exception (const xtd::string &message, const xtd::string &help_link, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class format_exception.
 
 format_exception (const xtd::string &message, const std::error_code &error, const xtd::string &help_link, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class format_exception.
 
 format_exception (const std::exception &inner_exception, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class format_exception.
 
 format_exception (const xtd::string &message, const std::exception &inner_exception, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class format_exception.
 
 format_exception (const xtd::string &message, const std::exception &inner_exception, const std::error_code &error, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class format_exception.
 
 format_exception (const xtd::string &message, const std::exception &inner_exception, const xtd::string &help_link, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class format_exception.
 
 format_exception (const xtd::string &message, const std::exception &inner_exception, const std::error_code &error, const xtd::string &help_link, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class format_exception.
 

Additional Inherited Members

- Public Types inherited from xtd::exception
using exception_ref = xtd::optional< std::reference_wrapper< const xtd::exception > >
 Optional reference wrapper on std::exception.
 
- Public Member Functions inherited from xtd::system_exception
 system_exception (const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class xtd::system_exception.
 
 system_exception (const xtd::optional< xtd::string > &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class xtd::system_exception.
 
template<typename exception_t >
 system_exception (const xtd::optional< xtd::string > &message, const exception_t &inner_exception, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class xtd::system_exception.
 
 system_exception (const xtd::string &message, const std::error_code &error, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class xtd::system_exception.
 
 system_exception (const xtd::string &message, const xtd::string &help_link, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class xtd::system_exception.
 
 system_exception (const xtd::string &message, const std::error_code &error, const xtd::string &help_link, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class xtd::system_exception.
 
 system_exception (const std::exception &inner_exception, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class xtd::system_exception.
 
 system_exception (const xtd::string &message, const std::exception &inner_exception, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class xtd::system_exception.
 
 system_exception (const xtd::string &message, const std::exception &inner_exception, const std::error_code &error, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class xtd::system_exception.
 
 system_exception (const xtd::string &message, const std::exception &inner_exception, const xtd::string &help_link, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class xtd::system_exception.
 
 system_exception (const xtd::string &message, const std::exception &inner_exception, const std::error_code &error, const xtd::string &help_link, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class xtd::system_exception.
 
virtual const xtd::stringfile_path () const noexcept
 Gets file path where exception occurred.
 
virtual xtd::size line_number () const noexcept
 Gets Line number where the exception occurred.
 
virtual const xtd::stringmember_name () const noexcept
 Gets file member where exception occurred.
 
virtual const xtd::stringname () const noexcept
 Gets full class name the exception.
 
- Public Member Functions inherited from xtd::exception
 exception (const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class exception.
 
 exception (const xtd::optional< xtd::string > &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class exception.
 
template<typename exception_t >
 exception (const xtd::optional< xtd::string > &message, const exception_t &inner_exception, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Create a new instance of class exception.
 
virtual const xtd::stringhelp_link () const noexcept
 Gets a link to the help file associated with this exception.
 
virtual void help_link (const xtd::string &value) noexcept
 Sets a link to the help file associated with this exception.
 
virtual int32 h_result () const noexcept
 Gets HRESULT, a coded numerical value that is assigned to a specific exception.
 
virtual void h_result (int32 value) noexcept
 Sets HRESULT, a coded numerical value that is assigned to a specific exception.
 
virtual const std::error_code & error_code () const noexcept
 Gets error associate to the exception.
 
virtual void error_code (const std::error_code &value) noexcept
 Sets error associate to the exception.
 
virtual exception_ref inner_exception () const noexcept
 Gets the exception instance that caused the current exception.
 
virtual const xtd::stringmessage () const noexcept
 Gets message associate to the exception.
 
virtual const xtd::stringsource () const noexcept
 Gets the name of the application or the object that causes the error.
 
virtual void source (const xtd::string &value) noexcept
 Sets the name of the application or the object that causes the error.
 
virtual xtd::string stack_trace () const noexcept
 Gets a string representation of the immediate frames on the call stack.
 
virtual const xtd::diagnostics::stack_frameget_last_stack_frame () const noexcept
 Gets the last stack frame where the exception occurred.
 
xtd::string to_string () const noexcept override
 Returns a string that represents the current exception.
 
const char * what () const noexcept override
 Gets message associate to the exception.
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
- Static Public Member Functions inherited from xtd::exception
static bool enable_stack_trace () noexcept
 Gets if the generation of the stack trace is enabled.
 
static void enable_stack_trace (bool enable) noexcept
 Sets if the generation of the stack trace is enabled. @paran enable triue if stack trace enabled; otherwhise false.
 
- Static Public Member Functions inherited from xtd::object
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<typename object_a_t , typename object_b_t >
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Constructor & Destructor Documentation

◆ format_exception() [1/11]

xtd::format_exception::format_exception ( const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current())
explicit

Create a new instance of class format_exception.

Parameters
stack_frame(optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current().
Remarks
Message is set with the default message associate to the exception.

◆ format_exception() [2/11]

xtd::format_exception::format_exception ( const std::optional< xtd::string > &  message,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
explicit

Create a new instance of class format_exception.

Parameters
messageMessage string associate to the exception.
stack_frame(optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current().

◆ format_exception() [3/11]

template<typename exception_t >
xtd::format_exception::format_exception ( const std::optional< xtd::string > &  message,
const exception_t &  inner_exception,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
inline

Create a new instance of class format_exception.

Parameters
messageMessage string associate to the exception.
inner_exceptionThe exception that is the cause of the current exception.
stack_frame(optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current().

◆ format_exception() [4/11]

xtd::format_exception::format_exception ( const xtd::string message,
const std::error_code &  error,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)

Create a new instance of class format_exception.

Parameters
messageMessage string associate to the exception.
errorError code associate to the exception.
stack_frame(optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current().
Deprecated:
Use xtd::format_exception (const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame) and manually set the property xtd::exception::error_code - Will be removed in version 0.4.0.

◆ format_exception() [5/11]

xtd::format_exception::format_exception ( const xtd::string message,
const xtd::string help_link,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)

Create a new instance of class format_exception.

Parameters
messageMessage string associate to the exception.
help_linkHelp link string associate to the exception.
stack_frame(optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current().
Deprecated:
Use xtd::format_exception (const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame) and manually set the property xtd::exception::help_link - Will be removed in version 0.4.0.

◆ format_exception() [6/11]

xtd::format_exception::format_exception ( const xtd::string message,
const std::error_code &  error,
const xtd::string help_link,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)

Create a new instance of class format_exception.

Parameters
messageMessage string associate to the exception.
errorError code associate to the exception.
help_linkHelp link string associate to the exception.
stack_frame(optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current().
Deprecated:
Use xtd::format_exception (const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame) and manually set the properties xtd::exception::error_code and xtd::exception::help_link - Will be removed in version 0.4.0.

◆ format_exception() [7/11]

xtd::format_exception::format_exception ( const std::exception &  inner_exception,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)

Create a new instance of class format_exception.

Parameters
inner_exceptionThe exception that is the cause of the current exception.
stack_frame(optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current().
Remarks
Message is set with the default message associate to the exception.
Deprecated:
Use xtd::format_exception (const xtd::string& message, const exception_t& inner_exception, const xtd::diagnostics::stack_frame& stack_frame) - Will be removed in version 0.4.0.

◆ format_exception() [8/11]

xtd::format_exception::format_exception ( const xtd::string message,
const std::exception &  inner_exception,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)

Create a new instance of class format_exception.

Parameters
messageMessage string associate to the exception.
inner_exceptionThe exception that is the cause of the current exception.
stack_frame(optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current().
Deprecated:
Use xtd::format_exception (const xtd::string& message, const exception_t& inner_exception, const xtd::diagnostics::stack_frame& stack_frame) - Will be removed in version 0.4.0.

◆ format_exception() [9/11]

xtd::format_exception::format_exception ( const xtd::string message,
const std::exception &  inner_exception,
const std::error_code &  error,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)

Create a new instance of class format_exception.

Parameters
messageMessage string associate to the exception.
inner_exceptionThe exception that is the cause of the current exception.
errorError code associate to the exception.
stack_frame(optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current().
Deprecated:
Use xtd::format_exception (const xtd::string& message, const exception_t& inner_exception, const xtd::diagnostics::stack_frame& stack_frame) and manually set the property xtd::exception::error_code - Will be removed in version 0.4.0.

◆ format_exception() [10/11]

xtd::format_exception::format_exception ( const xtd::string message,
const std::exception &  inner_exception,
const xtd::string help_link,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)

Create a new instance of class format_exception.

Parameters
messageMessage string associate to the exception.
inner_exceptionThe exception that is the cause of the current exception.
help_linkHelp link string associate to the exception.
stack_frame(optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current().
Deprecated:
Use xtd::format_exception (const xtd::string& message, const exception_t& inner_exception, const xtd::diagnostics::stack_frame& stack_frame) and manually set the property xtd::exception::help_link - Will be removed in version 0.4.0.

◆ format_exception() [11/11]

xtd::format_exception::format_exception ( const xtd::string message,
const std::exception &  inner_exception,
const std::error_code &  error,
const xtd::string help_link,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)

Create a new instance of class format_exception.

Parameters
messageMessage string associate to the exception.
inner_exceptionThe exception that is the cause of the current exception.
errorError code associate to the exception.
help_linkHelp link string associate to the exception.
stack_frame(optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current().
Deprecated:
Use xtd::format_exception (const xtd::string& message, const exception_t& inner_exception, const xtd::diagnostics::stack_frame& stack_frame) and manually set the properties xtd::exception::error_code and xtd::exception::help_link - Will be removed in version 0.4.0.

The documentation for this class was generated from the following file: