Path: blob/master/3rdparty/openexr/Iex/IexThrowErrnoExc.h
16337 views
///////////////////////////////////////////////////////////////////////////1//2// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas3// Digital Ltd. LLC4//5// All rights reserved.6//7// Redistribution and use in source and binary forms, with or without8// modification, are permitted provided that the following conditions are9// met:10// * Redistributions of source code must retain the above copyright11// notice, this list of conditions and the following disclaimer.12// * Redistributions in binary form must reproduce the above13// copyright notice, this list of conditions and the following disclaimer14// in the documentation and/or other materials provided with the15// distribution.16// * Neither the name of Industrial Light & Magic nor the names of17// its contributors may be used to endorse or promote products derived18// from this software without specific prior written permission.19//20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31//32///////////////////////////////////////////////////////////////////////////33343536#ifndef INCLUDED_IEXTHROWERRNOEXC_H37#define INCLUDED_IEXTHROWERRNOEXC_H3839//----------------------------------------------------------40//41// A function which throws ExcErrno exceptions42//43//----------------------------------------------------------4445#include "IexBaseExc.h"4647namespace Iex {484950//--------------------------------------------------------------------------51//52// Function throwErrnoExc() throws an exception which corresponds to53// error code errnum. The exception text is initialized with a copy54// of the string passed to throwErrnoExc(), where all occurrences of55// "%T" have been replaced with the output of strerror(oserror()).56//57// Example:58//59// If opening file /tmp/output failed with an ENOENT error code,60// calling61//62// throwErrnoExc ();63//64// or65//66// throwErrnoExc ("%T.");67//68// will throw an EnoentExc whose text reads69//70// No such file or directory.71//72// More detailed messages can be assembled using stringstreams:73//74// std::stringstream s;75// s << "Cannot open file " << name << " (%T).";76// throwErrnoExc (s);77//78// The resulting exception contains the following text:79//80// Cannot open file /tmp/output (No such file or directory).81//82// Alternatively, you may want to use the THROW_ERRNO macro defined83// in IexMacros.h:84//85// THROW_ERRNO ("Cannot open file " << name << " (%T).")86//87//--------------------------------------------------------------------------8889void throwErrnoExc (const std::string &txt, int errnum);90void throwErrnoExc (const std::string &txt = "%T." /*, int errnum = oserror() */);919293} // namespace Iex9495#endif969798