Back to Arangodb

Boost Exception

3rdParty/boost/1.78.0/libs/exception/doc/errinfo_file_handle.html

3.12.9.13.2 KB
Original Source

Boost Exception

errinfo_file_handle

#include <boost/exception/errinfo_file_handle.hpp>

#include <[boost/exception/error\_info.hpp](boost_exception_error_info_hpp.html)>

namespace
boost
    {
    template <class> class weak_ptr;typedef [error\_info](error_info.html)\<struct errinfo\_file\_handle\_,weak\_ptr\<FILE\> \> errinfo\_file\_handle;}

This type is designed to be used as a standard error_info instance for transporting a relevant FILE pointer managed by a boost::shared_ptr<FILE> in exceptions deriving from boost::exception.

Example:

#include <[boost/exception/errinfo\_api\_function.hpp](boost_exception_errinfo_api_function_hpp.html)>
#include <[boost/exception/errinfo\_at\_line.hpp](boost_exception_errinfo_at_line_hpp.html)>
#include <[boost/exception/errinfo\_errno.hpp](boost_exception_errinfo_errno_hpp.html)>
#include <[boost/exception/errinfo\_file\_handle.hpp](boost_exception_errinfo_file_handle_hpp.html)>
#include <[boost/exception/errinfo\_file\_name.hpp](boost_exception_errinfo_file_name_hpp.html)>
#include <[boost/exception/errinfo\_file\_open\_mode.hpp](boost_exception_errinfo_file_open_mode_hpp.html)>
#include <[boost/exception/info.hpp](boost_exception_info_hpp.html)>
#include <[boost/throw\_exception.hpp](boost_throw_exception_hpp.html)>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <stdio.h>
#include <errno.h>
#include <exception>

struct error : virtual std::exception, virtual boost::[exception](exception.html){ };
struct file_error : virtual error { };
struct file_open_error: virtual file_error { };
struct file_read_error: virtual file_error { };

boost::shared_ptr<FILE>
open_file( char const * file, char const * mode )
    {
    if( FILE * f=fopen(file,mode) )
        return boost::shared_ptr<FILE>(f,fclose);
    else[BOOST\_THROW\_EXCEPTION](BOOST_THROW_EXCEPTION.html)(
            file_open_error() <<
            boost::[errinfo\_api\_function](errinfo_api_function.html)("fopen") <<
            boost::[errinfo\_errno](errinfo_errno.html)(errno) <<
            boost::[errinfo\_file\_name](errinfo_file_name.html)(file) <<
            boost::[errinfo\_file\_open\_mode](errinfo_file_open_mode.html)(mode) );
    }

size_t
read_file( boost::shared_ptr<FILE> const & f, void * buf, size_t size )
    {
    size_t nr=fread(buf,1,size,f.get());
    if( ferror(f.get()) )[BOOST\_THROW\_EXCEPTION](BOOST_THROW_EXCEPTION.html)(
            file_read_error() <<
            boost::[errinfo\_api\_function](errinfo_api_function.html)("fread") <<
            boost::[errinfo\_errno](errinfo_errno.html)(errno) <<
            boost::errinfo\_file\_handle(f) );
    return nr;
    }

See also: boost/exception/errinfo_file_handle.hpp

Copyright (c) 2006-2009 by Emil Dotchevski and Reverge Studios, Inc.
Distributed under the Boost Software License, Version 1.0.