Blame Iex/IexThrowErrnoExc.h

Packit 8dc392
///////////////////////////////////////////////////////////////////////////
Packit 8dc392
//
Packit 8dc392
// Copyright (c) 2002-2012, Industrial Light & Magic, a division of Lucas
Packit 8dc392
// Digital Ltd. LLC
Packit 8dc392
// 
Packit 8dc392
// All rights reserved.
Packit 8dc392
// 
Packit 8dc392
// Redistribution and use in source and binary forms, with or without
Packit 8dc392
// modification, are permitted provided that the following conditions are
Packit 8dc392
// met:
Packit 8dc392
// *       Redistributions of source code must retain the above copyright
Packit 8dc392
// notice, this list of conditions and the following disclaimer.
Packit 8dc392
// *       Redistributions in binary form must reproduce the above
Packit 8dc392
// copyright notice, this list of conditions and the following disclaimer
Packit 8dc392
// in the documentation and/or other materials provided with the
Packit 8dc392
// distribution.
Packit 8dc392
// *       Neither the name of Industrial Light & Magic nor the names of
Packit 8dc392
// its contributors may be used to endorse or promote products derived
Packit 8dc392
// from this software without specific prior written permission. 
Packit 8dc392
// 
Packit 8dc392
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit 8dc392
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit 8dc392
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit 8dc392
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit 8dc392
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit 8dc392
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit 8dc392
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit 8dc392
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit 8dc392
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit 8dc392
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 8dc392
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 8dc392
//
Packit 8dc392
///////////////////////////////////////////////////////////////////////////
Packit 8dc392
Packit 8dc392
Packit 8dc392
Packit 8dc392
#ifndef INCLUDED_IEXTHROWERRNOEXC_H
Packit 8dc392
#define INCLUDED_IEXTHROWERRNOEXC_H
Packit 8dc392
Packit 8dc392
//----------------------------------------------------------
Packit 8dc392
//
Packit 8dc392
//	A function which throws ExcErrno exceptions
Packit 8dc392
//
Packit 8dc392
//----------------------------------------------------------
Packit 8dc392
Packit 8dc392
#include "IexBaseExc.h"
Packit 8dc392
#include "IexExport.h"
Packit 8dc392
Packit 8dc392
IEX_INTERNAL_NAMESPACE_HEADER_ENTER
Packit 8dc392
Packit 8dc392
Packit 8dc392
//--------------------------------------------------------------------------
Packit 8dc392
//
Packit 8dc392
// Function throwErrnoExc() throws an exception which corresponds to
Packit 8dc392
// error code errnum.  The exception text is initialized with a copy
Packit 8dc392
// of the string passed to throwErrnoExc(), where all occurrences of
Packit 8dc392
// "%T" have been replaced with the output of strerror(oserror()).
Packit 8dc392
//
Packit 8dc392
// Example:
Packit 8dc392
//   
Packit 8dc392
// If opening file /tmp/output failed with an ENOENT error code,
Packit 8dc392
// calling
Packit 8dc392
//
Packit 8dc392
//	throwErrnoExc ();
Packit 8dc392
//
Packit 8dc392
// or
Packit 8dc392
//
Packit 8dc392
//	throwErrnoExc ("%T.");
Packit 8dc392
//
Packit 8dc392
// will throw an EnoentExc whose text reads
Packit 8dc392
//
Packit 8dc392
//	No such file or directory.
Packit 8dc392
//
Packit 8dc392
// More detailed messages can be assembled using stringstreams:
Packit 8dc392
//
Packit 8dc392
//	std::stringstream s;
Packit 8dc392
//	s << "Cannot open file " << name << " (%T).";
Packit 8dc392
//	throwErrnoExc (s);
Packit 8dc392
//
Packit 8dc392
// The resulting exception contains the following text:
Packit 8dc392
//
Packit 8dc392
//	Cannot open file /tmp/output (No such file or directory).
Packit 8dc392
//
Packit 8dc392
// Alternatively, you may want to use the THROW_ERRNO macro defined
Packit 8dc392
// in IexMacros.h:
Packit 8dc392
//
Packit 8dc392
//	THROW_ERRNO ("Cannot open file " << name << " (%T).")
Packit 8dc392
//
Packit 8dc392
//--------------------------------------------------------------------------
Packit 8dc392
Packit 8dc392
IEX_EXPORT void throwErrnoExc(const std::string &txt, int errnum);
Packit 8dc392
IEX_EXPORT void throwErrnoExc(const std::string &txt);
Packit 8dc392
IEX_EXPORT void throwErrnoExc();
Packit 8dc392
Packit 8dc392
IEX_INTERNAL_NAMESPACE_HEADER_EXIT
Packit 8dc392
Packit 8dc392
#endif // INCLUDED_IEXTHROWERRNOEXC_H