///////////////////////////////////////////////////////////////////////////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_IEXMACROS_H37#define INCLUDED_IEXMACROS_H3839//--------------------------------------------------------------------40//41// Macros which make throwing exceptions more convenient42//43//--------------------------------------------------------------------4445#include <sstream>464748//----------------------------------------------------------------------------49// A macro to throw exceptions whose text is assembled using stringstreams.50//51// Example:52//53// THROW (InputExc, "Syntax error in line " << line ", " << file << ".");54//55//----------------------------------------------------------------------------5657#define THROW(type, text) \58do \59{ \60std::stringstream s; \61s << text; \62throw type (s); \63} \64while (0)656667//----------------------------------------------------------------------------68// Macros to add to or to replace the text of an exception.69// The new text is assembled using stringstreams.70//71// Examples:72//73// Append to end of an exception's text:74//75// catch (BaseExc &e)76// {77// APPEND_EXC (e, " Directory " << name << " does not exist.");78// throw;79// }80//81// Replace an exception's text:82//83// catch (BaseExc &e)84// {85// REPLACE_EXC (e, "Directory " << name << " does not exist. " << e);86// throw;87// }88//----------------------------------------------------------------------------8990#define APPEND_EXC(exc, text) \91do \92{ \93std::stringstream s; \94s << text; \95exc.append (s); \96} \97while (0)9899#define REPLACE_EXC(exc, text) \100do \101{ \102std::stringstream s; \103s << text; \104exc.assign (s); \105} \106while (0)107108109//-------------------------------------------------------------110// A macro to throw ErrnoExc exceptions whose text is assembled111// using stringstreams:112//113// Example:114//115// THROW_ERRNO ("Cannot open file " << name << " (%T).");116//117//-------------------------------------------------------------118119#define THROW_ERRNO(text) \120do \121{ \122std::stringstream s; \123s << text; \124::Iex::throwErrnoExc (s.str()); \125} \126while (0)127128129//-------------------------------------------------------------130// A macro to throw exceptions if an assertion is false.131//132// Example:133//134// ASSERT (ptr != NULL, NullExc, "Null pointer" );135//136//-------------------------------------------------------------137138#define ASSERT(assertion, type, text) \139do \140{ \141if ((assertion) == false) \142THROW (type, text); \143} \144while (0)145146147#endif148149150