Path: blob/master/3rdparty/openexr/Iex/IexThrowErrnoExc.cpp
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//----------------------------------------------------------------37//38// Exceptions that correspond to "errno" error codes,39// and a function to make throwing those exceptions easy.40//41//----------------------------------------------------------------4243#include "IexThrowErrnoExc.h"44#include "IexErrnoExc.h"45#include <string.h>46#include <errno.h>4748namespace Iex {495051void throwErrnoExc (const std::string &text, int errnum)52{53const char *entext = strerror (errnum);54std::string tmp (text);55std::string::size_type pos;5657while (std::string::npos != (pos = tmp.find ("%T")))58tmp.replace (pos, 2, entext, strlen (entext));5960switch (errnum)61{62#if defined (EPERM)63case EPERM:64throw EpermExc (tmp);65#endif6667#if defined (ENOENT)68case ENOENT:69throw EnoentExc (tmp);70#endif7172#if defined (ESRCH)73case ESRCH:74throw EsrchExc (tmp);75#endif7677#if defined (EINTR)78case EINTR:79throw EintrExc (tmp);80#endif8182#if defined (EIO)83case EIO:84throw EioExc (tmp);85#endif8687#if defined (ENXIO)88case ENXIO:89throw EnxioExc (tmp);90#endif9192#if defined (E2BIG)93case E2BIG:94throw E2bigExc (tmp);95#endif9697#if defined (ENOEXEC)98case ENOEXEC:99throw EnoexecExc (tmp);100#endif101102#if defined (EBADF)103case EBADF:104throw EbadfExc (tmp);105#endif106107#if defined (ECHILD)108case ECHILD:109throw EchildExc (tmp);110#endif111112#if defined (EAGAIN)113case EAGAIN:114throw EagainExc (tmp);115#endif116117#if defined (ENOMEM)118case ENOMEM:119throw EnomemExc (tmp);120#endif121122#if defined (EACCES)123case EACCES:124throw EaccesExc (tmp);125#endif126127#if defined (EFAULT)128case EFAULT:129throw EfaultExc (tmp);130#endif131132#if defined (ENOTBLK)133case ENOTBLK:134throw EnotblkExc (tmp);135#endif136137#if defined (EBUSY)138case EBUSY:139throw EbusyExc (tmp);140#endif141142#if defined (EEXIST)143case EEXIST:144throw EexistExc (tmp);145#endif146147#if defined (EXDEV)148case EXDEV:149throw ExdevExc (tmp);150#endif151152#if defined (ENODEV)153case ENODEV:154throw EnodevExc (tmp);155#endif156157#if defined (ENOTDIR)158case ENOTDIR:159throw EnotdirExc (tmp);160#endif161162#if defined (EISDIR)163case EISDIR:164throw EisdirExc (tmp);165#endif166167#if defined (EINVAL)168case EINVAL:169throw EinvalExc (tmp);170#endif171172#if defined (ENFILE)173case ENFILE:174throw EnfileExc (tmp);175#endif176177#if defined (EMFILE)178case EMFILE:179throw EmfileExc (tmp);180#endif181182#if defined (ENOTTY)183case ENOTTY:184throw EnottyExc (tmp);185#endif186187#if defined (ETXTBSY)188case ETXTBSY:189throw EtxtbsyExc (tmp);190#endif191192#if defined (EFBIG)193case EFBIG:194throw EfbigExc (tmp);195#endif196197#if defined (ENOSPC)198case ENOSPC:199throw EnospcExc (tmp);200#endif201202#if defined (ESPIPE)203case ESPIPE:204throw EspipeExc (tmp);205#endif206207#if defined (EROFS)208case EROFS:209throw ErofsExc (tmp);210#endif211212#if defined (EMLINK)213case EMLINK:214throw EmlinkExc (tmp);215#endif216217#if defined (EPIPE)218case EPIPE:219throw EpipeExc (tmp);220#endif221222#if defined (EDOM)223case EDOM:224throw EdomExc (tmp);225#endif226227#if defined (ERANGE)228case ERANGE:229throw ErangeExc (tmp);230#endif231232#if defined (ENOMSG)233case ENOMSG:234throw EnomsgExc (tmp);235#endif236237#if defined (EIDRM)238case EIDRM:239throw EidrmExc (tmp);240#endif241242#if defined (ECHRNG)243case ECHRNG:244throw EchrngExc (tmp);245#endif246247#if defined (EL2NSYNC)248case EL2NSYNC:249throw El2nsyncExc (tmp);250#endif251252#if defined (EL3HLT)253case EL3HLT:254throw El3hltExc (tmp);255#endif256257#if defined (EL3RST)258case EL3RST:259throw El3rstExc (tmp);260#endif261262#if defined (ELNRNG)263case ELNRNG:264throw ElnrngExc (tmp);265#endif266267#if defined (EUNATCH)268case EUNATCH:269throw EunatchExc (tmp);270#endif271272#if defined (ENOSCI)273case ENOCSI:274throw EnocsiExc (tmp);275#endif276277#if defined (EL2HLT)278case EL2HLT:279throw El2hltExc (tmp);280#endif281282#if defined (EDEADLK)283case EDEADLK:284throw EdeadlkExc (tmp);285#endif286287#if defined (ENOLCK)288case ENOLCK:289throw EnolckExc (tmp);290#endif291292#if defined (EBADE)293case EBADE:294throw EbadeExc (tmp);295#endif296297#if defined (EBADR)298case EBADR:299throw EbadrExc (tmp);300#endif301302#if defined (EXFULL)303case EXFULL:304throw ExfullExc (tmp);305#endif306307#if defined (ENOANO)308case ENOANO:309throw EnoanoExc (tmp);310#endif311312#if defined (EBADRQC)313case EBADRQC:314throw EbadrqcExc (tmp);315#endif316317#if defined (EBADSLT)318case EBADSLT:319throw EbadsltExc (tmp);320#endif321322#if defined (EDEADLOCK) && defined (EDEADLK)323#if EDEADLOCK != EDEADLK324case EDEADLOCK:325throw EdeadlockExc (tmp);326#endif327#elif defined (EDEADLOCK)328case EDEADLOCK:329throw EdeadlockExc (tmp);330#endif331332#if defined (EBFONT)333case EBFONT:334throw EbfontExc (tmp);335#endif336337#if defined (ENOSTR)338case ENOSTR:339throw EnostrExc (tmp);340#endif341342#if defined (ENODATA)343case ENODATA:344throw EnodataExc (tmp);345#endif346347#if defined (ETIME)348case ETIME:349throw EtimeExc (tmp);350#endif351352#if defined (ENOSR)353case ENOSR:354throw EnosrExc (tmp);355#endif356357#if defined (ENONET)358case ENONET:359throw EnonetExc (tmp);360#endif361362#if defined (ENOPKG)363case ENOPKG:364throw EnopkgExc (tmp);365#endif366367#if defined (EREMOTE)368case EREMOTE:369throw EremoteExc (tmp);370#endif371372#if defined (ENOLINK)373case ENOLINK:374throw EnolinkExc (tmp);375#endif376377#if defined (EADV)378case EADV:379throw EadvExc (tmp);380#endif381382#if defined (ESRMNT)383case ESRMNT:384throw EsrmntExc (tmp);385#endif386387#if defined (ECOMM)388case ECOMM:389throw EcommExc (tmp);390#endif391392#if defined (EPROTO)393case EPROTO:394throw EprotoExc (tmp);395#endif396397#if defined (EMULTIHOP)398case EMULTIHOP:399throw EmultihopExc (tmp);400#endif401402#if defined (EBADMSG)403case EBADMSG:404throw EbadmsgExc (tmp);405#endif406407#if defined (ENAMETOOLONG)408case ENAMETOOLONG:409throw EnametoolongExc (tmp);410#endif411412#if defined (EOVERFLOW)413case EOVERFLOW:414throw EoverflowExc (tmp);415#endif416417#if defined (ENOTUNIQ)418case ENOTUNIQ:419throw EnotuniqExc (tmp);420#endif421422#if defined (EBADFD)423case EBADFD:424throw EbadfdExc (tmp);425#endif426427#if defined (EREMCHG)428case EREMCHG:429throw EremchgExc (tmp);430#endif431432#if defined (ELIBACC)433case ELIBACC:434throw ElibaccExc (tmp);435#endif436437#if defined (ELIBBAD)438case ELIBBAD:439throw ElibbadExc (tmp);440#endif441442#if defined (ELIBSCN)443case ELIBSCN:444throw ElibscnExc (tmp);445#endif446447#if defined (ELIBMAX)448case ELIBMAX:449throw ElibmaxExc (tmp);450#endif451452#if defined (ELIBEXEC)453case ELIBEXEC:454throw ElibexecExc (tmp);455#endif456457#if defined (EILSEQ)458case EILSEQ:459throw EilseqExc (tmp);460#endif461462#if defined (ENOSYS)463case ENOSYS:464throw EnosysExc (tmp);465#endif466467#if defined (ELOOP)468case ELOOP:469throw EloopExc (tmp);470#endif471472#if defined (ERESTART)473case ERESTART:474throw ErestartExc (tmp);475#endif476477#if defined (ESTRPIPE)478case ESTRPIPE:479throw EstrpipeExc (tmp);480#endif481482#if defined (ENOTEMPTY)483case ENOTEMPTY:484throw EnotemptyExc (tmp);485#endif486487#if defined (EUSERS)488case EUSERS:489throw EusersExc (tmp);490#endif491492#if defined (ENOTSOCK)493case ENOTSOCK:494throw EnotsockExc (tmp);495#endif496497#if defined (EDESTADDRREQ)498case EDESTADDRREQ:499throw EdestaddrreqExc (tmp);500#endif501502#if defined (EMSGSIZE)503case EMSGSIZE:504throw EmsgsizeExc (tmp);505#endif506507#if defined (EPROTOTYPE)508case EPROTOTYPE:509throw EprototypeExc (tmp);510#endif511512#if defined (ENOPROTOOPT)513case ENOPROTOOPT:514throw EnoprotooptExc (tmp);515#endif516517#if defined (EPROTONOSUPPORT)518case EPROTONOSUPPORT:519throw EprotonosupportExc (tmp);520#endif521522#if defined (ESOCKTNOSUPPORT)523case ESOCKTNOSUPPORT:524throw EsocktnosupportExc (tmp);525#endif526527#if defined (EOPNOTSUPP)528case EOPNOTSUPP:529throw EopnotsuppExc (tmp);530#endif531532#if defined (EPFNOSUPPORT)533case EPFNOSUPPORT:534throw EpfnosupportExc (tmp);535#endif536537#if defined (EAFNOSUPPORT)538case EAFNOSUPPORT:539throw EafnosupportExc (tmp);540#endif541542#if defined (EADDRINUSE)543case EADDRINUSE:544throw EaddrinuseExc (tmp);545#endif546547#if defined (EADDRNOTAVAIL)548case EADDRNOTAVAIL:549throw EaddrnotavailExc (tmp);550#endif551552#if defined (ENETDOWN)553case ENETDOWN:554throw EnetdownExc (tmp);555#endif556557#if defined (ENETUNREACH)558case ENETUNREACH:559throw EnetunreachExc (tmp);560#endif561562#if defined (ENETRESET)563case ENETRESET:564throw EnetresetExc (tmp);565#endif566567#if defined (ECONNABORTED)568case ECONNABORTED:569throw EconnabortedExc (tmp);570#endif571572#if defined (ECONNRESET)573case ECONNRESET:574throw EconnresetExc (tmp);575#endif576577#if defined (ENOBUFS)578case ENOBUFS:579throw EnobufsExc (tmp);580#endif581582#if defined (EISCONN)583case EISCONN:584throw EisconnExc (tmp);585#endif586587#if defined (ENOTCONN)588case ENOTCONN:589throw EnotconnExc (tmp);590#endif591592#if defined (ESHUTDOWN)593case ESHUTDOWN:594throw EshutdownExc (tmp);595#endif596597#if defined (ETOOMANYREFS)598case ETOOMANYREFS:599throw EtoomanyrefsExc (tmp);600#endif601602#if defined (ETIMEDOUT)603case ETIMEDOUT:604throw EtimedoutExc (tmp);605#endif606607#if defined (ECONNREFUSED)608case ECONNREFUSED:609throw EconnrefusedExc (tmp);610#endif611612#if defined (EHOSTDOWN)613case EHOSTDOWN:614throw EhostdownExc (tmp);615#endif616617#if defined (EHOSTUNREACH)618case EHOSTUNREACH:619throw EhostunreachExc (tmp);620#endif621622#if defined (EALREADY)623case EALREADY:624throw EalreadyExc (tmp);625#endif626627#if defined (EINPROGRESS)628case EINPROGRESS:629throw EinprogressExc (tmp);630#endif631632#if defined (ESTALE)633case ESTALE:634throw EstaleExc (tmp);635#endif636637#if defined (EIORESID)638case EIORESID:639throw EioresidExc (tmp);640#endif641642#if defined (EUCLEAN)643case EUCLEAN:644throw EucleanExc (tmp);645#endif646647#if defined (ENOTNAM)648case ENOTNAM:649throw EnotnamExc (tmp);650#endif651652#if defined (ENAVAIL)653case ENAVAIL:654throw EnavailExc (tmp);655#endif656657#if defined (EISNAM)658case EISNAM:659throw EisnamExc (tmp);660#endif661662#if defined (EREMOTEIO)663case EREMOTEIO:664throw EremoteioExc (tmp);665#endif666667#if defined (EINIT)668case EINIT:669throw EinitExc (tmp);670#endif671672#if defined (EREMDEV)673case EREMDEV:674throw EremdevExc (tmp);675#endif676677#if defined (ECANCELED)678case ECANCELED:679throw EcanceledExc (tmp);680#endif681682#if defined (ENOLIMFILE)683case ENOLIMFILE:684throw EnolimfileExc (tmp);685#endif686687#if defined (EPROCLIM)688case EPROCLIM:689throw EproclimExc (tmp);690#endif691692#if defined (EDISJOINT)693case EDISJOINT:694throw EdisjointExc (tmp);695#endif696697#if defined (ENOLOGIN)698case ENOLOGIN:699throw EnologinExc (tmp);700#endif701702#if defined (ELOGINLIM)703case ELOGINLIM:704throw EloginlimExc (tmp);705#endif706707#if defined (EGROUPLOOP)708case EGROUPLOOP:709throw EgrouploopExc (tmp);710#endif711712#if defined (ENOATTACH)713case ENOATTACH:714throw EnoattachExc (tmp);715#endif716717#if defined (ENOTSUP) && defined (EOPNOTSUPP)718#if ENOTSUP != EOPNOTSUPP719case ENOTSUP:720throw EnotsupExc (tmp);721#endif722#elif defined (ENOTSUP)723case ENOTSUP:724throw EnotsupExc (tmp);725#endif726727#if defined (ENOATTR)728case ENOATTR:729throw EnoattrExc (tmp);730#endif731732#if defined (EDIRCORRUPTED)733case EDIRCORRUPTED:734throw EdircorruptedExc (tmp);735#endif736737#if defined (EDQUOT)738case EDQUOT:739throw EdquotExc (tmp);740#endif741742#if defined (ENFSREMOTE)743case ENFSREMOTE:744throw EnfsremoteExc (tmp);745#endif746747#if defined (ECONTROLLER)748case ECONTROLLER:749throw EcontrollerExc (tmp);750#endif751752#if defined (ENOTCONTROLLER)753case ENOTCONTROLLER:754throw EnotcontrollerExc (tmp);755#endif756757#if defined (EENQUEUED)758case EENQUEUED:759throw EenqueuedExc (tmp);760#endif761762#if defined (ENOTENQUEUED)763case ENOTENQUEUED:764throw EnotenqueuedExc (tmp);765#endif766767#if defined (EJOINED)768case EJOINED:769throw EjoinedExc (tmp);770#endif771772#if defined (ENOTJOINED)773case ENOTJOINED:774throw EnotjoinedExc (tmp);775#endif776777#if defined (ENOPROC)778case ENOPROC:779throw EnoprocExc (tmp);780#endif781782#if defined (EMUSTRUN)783case EMUSTRUN:784throw EmustrunExc (tmp);785#endif786787#if defined (ENOTSTOPPED)788case ENOTSTOPPED:789throw EnotstoppedExc (tmp);790#endif791792#if defined (ECLOCKCPU)793case ECLOCKCPU:794throw EclockcpuExc (tmp);795#endif796797#if defined (EINVALSTATE)798case EINVALSTATE:799throw EinvalstateExc (tmp);800#endif801802#if defined (ENOEXIST)803case ENOEXIST:804throw EnoexistExc (tmp);805#endif806807#if defined (EENDOFMINOR)808case EENDOFMINOR:809throw EendofminorExc (tmp);810#endif811812#if defined (EBUFSIZE)813case EBUFSIZE:814throw EbufsizeExc (tmp);815#endif816817#if defined (EEMPTY)818case EEMPTY:819throw EemptyExc (tmp);820#endif821822#if defined (ENOINTRGROUP)823case ENOINTRGROUP:824throw EnointrgroupExc (tmp);825#endif826827#if defined (EINVALMODE)828case EINVALMODE:829throw EinvalmodeExc (tmp);830#endif831832#if defined (ECANTEXTENT)833case ECANTEXTENT:834throw EcantextentExc (tmp);835#endif836837#if defined (EINVALTIME)838case EINVALTIME:839throw EinvaltimeExc (tmp);840#endif841842#if defined (EDESTROYED)843case EDESTROYED:844throw EdestroyedExc (tmp);845#endif846}847848throw ErrnoExc (tmp);849}850851852void throwErrnoExc (const std::string &text)853{854throwErrnoExc (text, errno);855}856857858} // namespace Iex859860861