includefile(include/header)

COMMENT(manpage, section, releasedate, archive, short name)
manpage(FBB::Exception)(3bobcat)(_CurYrs_)(libbobcat-dev__CurVers_)
                    (Error handler)

manpagename(FBB::Exception)(std::exception objects acception stream insertions)

manpagesynopsis()
    bf(#include <bobcat/exception>)nl()
    Linking option: tt(-lbobcat) 

manpagedescription()
       bf(FBB::Exception) objects derived from tt(std::exception), but accept
stream insertions. Their intended use consists of throwing an anonymous
object, into which the text of the tt(std::exception::what) 
message has been inserted.

    tt(Exception) exceptions are thrown by several Bobcat classes. These
classes are tt(
Arg, 
ArgConfig,
BigInt,
Cgi,
Cidr,
ClientSocket,
CmdFinderBase,
ConfigFile,
DateTime,
DecryptBuf,
DigestBuf,
EncryptBuf,
Fork,
GetHostent,
Glob,
HMacBuf,
Hostname,
LocalClientSocket,
LocalServerSocket,
LocalSocketBase,
Log,
MailHeaders,
Mbuf,
Milter,
Mstream,
OFoldBuf,
OneKey,
Pattern,
Pipe,
Process,
Redirector,
Selector,
ServerSocket,
Signal,
SocketBase,
Stat,
TempStream,
User,
Xpointer)


manpagesection(NAMESPACE)
    bf(FBB)nl()
    All constructors, members, operators and manipulators, mentioned in this
man-page, are defined in the namespace bf(FBB).

manpagesection(INHERITS FROM)
    bf(std::exception)

manpagesection(ENUMERATION)
    The enumeration tt(Protection) is used by the member tt(protection)
described below. The enumeration has two values:
    itemization(
    itt(ANY): an existing file may have any set of protection bits;
    itt(EQUAL): an existing file mut have exactly the set of protection bits
        as specified when calling tt(Exception::protection).
    )

manpagesection(CONSTRUCTORS)
    itemization(
    itb(Exception())
   The default constructor (assigns 0 to tt(FBB::g_errno), see the next
    constructor). 

    itb(Exception(int errnoValue)) 
   This constructor stores the provided tt(errnoValue) value in a thread-local
    variable tt(int FBB::g_errno). Before Bobcat 4.04.00 tt(errnoValue) was
    only stored in the global tt(::errno) variable (it still is), but as this
    variable is also used by many other functions, tt(errno's) value may have
    changed by the time the exception is caught. The tt(thread_local int
    FBB::g_errno) variable does not have that drawback.

    When tt(g_errno) must be declared without including  tt(bobcat/exception)
    then do
        verb(
    namespace FBB
    {
        extern thread_local int g_errno;
    }
        )
    )

    Copy and move constructors (and assignment operators) are available.

manpagesection(MEMBER FUNCTIONS)
     All members of bf(std::exception) are
available, as bf(FBB::Exception) inherits from this class.
    itemization(
    itb(char const *what() const noexcept(true) override) 
    Returns the text that was inserted into the bf(FBB::Exception) object.
    )

manpagesection(OVERLOADED OPERATORS)
    itemization(
    itb(Exception &&operator<<(Exception &&in, Type const &t))
    A function template implementing the overloaded insertion operator. It
can be used to insert values of any type that can also be inserted into an
tt(ostringstream) object.
    )


manpagesection(STATIC MEMBERS)

    The following convenience functions can be used for controlled opening of
stream-type objects, like tt(std::ofstream) and tt(std::ifstream)
objects. These stream-type objects must support tt(open) and tt(close)
members, like those provided by tt(std::ifstream) and tt(std::ofstream).

If the stream  was already open it is first closed.

If opening fails an tt(FBB::Exception) exception is thrown containing a
short message stating that the named stream could not be opened. 

    itemization(
    itb(static StreamType factory<StreamType>(std::string const &name))
       Returns an open tt(StreamType>) stream object which can be used to
        move-construct a tt(StreamType) object. E.g.,
            verb(
    auto out{ Exception::factory<ofstream>("/tmp/out") };
            )

    itb(static StreamType factory<StreamType>(int errnoValue, 
                                              std::string const &name))
        Returns an open tt(StreamType>) stream object which can be used to
        move-construct a tt(StreamType) object. If constructing
        the stream object fails, then the thrown bf(FBB::Exception) assigns
        tt(errnoValue) to tt(FBB::g_errno).

    itb(static StreamType factory<StreamType>(std::string const &name,
                                              std::ios::openmode mode))
       Returns an open tt(StreamType>) stream object, created using
        the tt(openmode mode) flags,  which can be used to
        move-construct a tt(StreamType) object.

    itb(static StreamType factory<StreamType>(int errnoValue,
                                              std::string const &name,
                                              std::ios::openmode mode))
       Returns an open tt(StreamType>) stream object, created using
        the tt(openmode mode) flags,  which can be used to
        move-construct a tt(StreamType) object.  If constructing
        the stream object fails, then the thrown bf(FBB::Exception) assigns
        tt(errnoValue) to tt(FBB::g_errno).

    itb(static StreamType factory<StreamType>(std::string const &name,
                                              std::ios::openmode mode1,
                                              std::ios::openmode mode2))
       Returns an open tt(StreamType>) stream object. the stream is initially
        opened using tt(mode1). If that fails, tt(mode2) is used. If both ways
        to open the stream fail, then an tt(Exception) is thrown.  The
        returned stream can be used to move-construct a tt(StreamType) object.
        This member can be used to open an tt(std::fstream) which may or may
        not yet exist for both reading and writing. E.g., 
            verb(
    auto out{ Exception::factory<fstream>("/tmp/out", 
                ios::in | ios::out,
                ios::in | ios::out | ios::trunc) };
            )
       If tt(/tmp/out) already exists, then tt(ios::in | ios::out) should
        succeed. If it doesn't, then it's created empty for reading and
        writing, using tt(ios::in | ios::out | ios::trunc).

    itb(static StreamType factory<StreamType>(int errnoValue,
                                              std::string const &name,
                                              std::ios::openmode mode1,
                                              std::ios::openmode mode2))
       Returns an open tt(StreamType>) stream object. the stream is initially
        opened using tt(mode1). If that fails, tt(mode2) is used. If both ways
        to open the stream fail, then an tt(Exception) is thrown, assigning
        tt(errnoValue) to tt(FBB::g_errno).

    itb(static void open(int errnoValue, StreamType &stream,
                        std::string const &name, std::ios::openmode mode))
       Opens the stream object, using its tt(open) member, passing tt(mode) to
        tt(open). If opening the stream fails, then the thrown
        bf(FBB::Exception) assigns tt(errnoValue) to tt(FBB::g_errno).

    itb(static void open(StreamType &stream, std::string const &name))
        Opens the stream object, using its default tt(open) member.

    itb(static void open(int errnoValue, 
                         StreamType &stream, std::string const &name))
       Opens the stream object, using its default tt(open) member. If opening
        the stream fails, then the thrown bf(FBB::Exception) assigns
        tt(errnoValue) to tt(FBB::g_errno).

    itb(static void open(StreamType &stream, std::string const &name,
                                    std::ios::openmode mode))
       Opens the stream object, using its tt(open) member, passing tt(mode) to
        tt(open).

    itb(static void open(int errnoValue, StreamType &stream,
                        std::string const &name, std::ios::openmode mode))
       Opens the stream object, using its tt(open) member, passing tt(mode) to
        tt(open). If opening the stream fails, then the thrown
        bf(FBB::Exception) assigns tt(errnoValue) to tt(FBB::g_errno).

    itb(static void open(StreamType &stream, std::string const &name,
                                    std::ios::openmode mode1,
                                    std::ios::openmode mode2))
       Opens the stream object, using its tt(open) member, , initially passing
        tt(mode1) to tt(open). If that fails, tt(mode2) is used. If both ways
        to open the stream fail, then an tt(Exception) is thrown.

    itb(static void open(int errnoValue, StreamType &stream,
                        std::string const &name, std::ios::openmode mode1,
                                    std::ios::openmode mode2))
       Opens the stream object, using its tt(open) member, initially passing
        tt(mode1) to tt(open). If that fails, tt(mode2) is used. If both ways
        to open the stream fail, then an tt(Exception) is thrown, assigning
        tt(errnoValue) to tt(FBB::g_errno).

    itb(static size_t protection(std::string const &path, size_t protect, 
                          Protection type = EQUAL))
       Returns the protection bits (cf. bf(open)(2)) of tt(path). The
        tt(protect) parameter is used to specify the requested protection
        bits. This value is usually specified as an octal value. If the
        specified value exceeds 0777 an exception is thrown. The third
        parameter is only used in combination with already existing files. If
        specified as tt(ANY) the file's actual permission bits are not
        compared with tt(protect); if specified as tt(EQUAL) the file's
        permission bits must be identical to tt(protect), or an exception is
        thrown. If tt(path) does not yet exist a file tt(path) with permission
        tt(protect) is created. This member returns tt(path)'s permission
        bits. 

        If tt(path) is created by tt(protection), then opening a stream for
        tt(path) does not change tt(path)'s protection. 
    )

manpagesection(MANIPULATOR)

    The following manipulator (which is em(not) part of the
bf(FBB::Exception), class, but em(is) defined in the bf(FBB) namespace) can be
inserted into the bf(FBB::Exception) object:
    itemization(
    itb(FBB::errnodescr) 
        The descriptive text associated with the current tt(errno) value is
inserted into the bf(FBB::Exception) object (it can also be used to insert the
descriptive text in a tt(std::ostream) object). No text is inserted if
tt(errno) equals zero. This manipulator is thread-safe (but tt(errno) may be
modified when tt(errno) holds an invalid value).
    )

manpagesection(EXAMPLE)
        verb(
    if (exceptionalCondition)
        throw FBB::Exception{ 1 } << "Exceptional condition occurred";
        )

manpagefiles()
    em(bobcat/exception) - defines the class interface

manpageseealso()
    bf(bobcat)(7)

manpagebugs()
    None Reported.

includefile(include/trailer)
