/src/FreeImage/Source/OpenEXR/Iex/IexThrowErrnoExc.cpp

https://bitbucket.org/cabalistic/ogredeps/ · C++ · 859 lines · 652 code · 168 blank · 39 comment · 7 complexity · e3fa4c87ad7cab942fcc32baf886c473 MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
  4. // Digital Ltd. LLC
  5. //
  6. // All rights reserved.
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions are
  10. // met:
  11. // * Redistributions of source code must retain the above copyright
  12. // notice, this list of conditions and the following disclaimer.
  13. // * Redistributions in binary form must reproduce the above
  14. // copyright notice, this list of conditions and the following disclaimer
  15. // in the documentation and/or other materials provided with the
  16. // distribution.
  17. // * Neither the name of Industrial Light & Magic nor the names of
  18. // its contributors may be used to endorse or promote products derived
  19. // from this software without specific prior written permission.
  20. //
  21. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. //
  33. ///////////////////////////////////////////////////////////////////////////
  34. //----------------------------------------------------------------
  35. //
  36. // Exceptions that correspond to "errno" error codes,
  37. // and a function to make throwing those exceptions easy.
  38. //
  39. //----------------------------------------------------------------
  40. #include "IexThrowErrnoExc.h"
  41. #include "IexErrnoExc.h"
  42. #include <string.h>
  43. #include <errno.h>
  44. namespace Iex {
  45. void throwErrnoExc (const std::string &text, int errnum)
  46. {
  47. const char *entext = strerror (errnum);
  48. std::string tmp (text);
  49. std::string::size_type pos;
  50. while (std::string::npos != (pos = tmp.find ("%T")))
  51. tmp.replace (pos, 2, entext, strlen (entext));
  52. switch (errnum)
  53. {
  54. #if defined (EPERM)
  55. case EPERM:
  56. throw EpermExc (tmp);
  57. #endif
  58. #if defined (ENOENT)
  59. case ENOENT:
  60. throw EnoentExc (tmp);
  61. #endif
  62. #if defined (ESRCH)
  63. case ESRCH:
  64. throw EsrchExc (tmp);
  65. #endif
  66. #if defined (EINTR)
  67. case EINTR:
  68. throw EintrExc (tmp);
  69. #endif
  70. #if defined (EIO)
  71. case EIO:
  72. throw EioExc (tmp);
  73. #endif
  74. #if defined (ENXIO)
  75. case ENXIO:
  76. throw EnxioExc (tmp);
  77. #endif
  78. #if defined (E2BIG)
  79. case E2BIG:
  80. throw E2bigExc (tmp);
  81. #endif
  82. #if defined (ENOEXEC)
  83. case ENOEXEC:
  84. throw EnoexecExc (tmp);
  85. #endif
  86. #if defined (EBADF)
  87. case EBADF:
  88. throw EbadfExc (tmp);
  89. #endif
  90. #if defined (ECHILD)
  91. case ECHILD:
  92. throw EchildExc (tmp);
  93. #endif
  94. #if defined (EAGAIN)
  95. case EAGAIN:
  96. throw EagainExc (tmp);
  97. #endif
  98. #if defined (ENOMEM)
  99. case ENOMEM:
  100. throw EnomemExc (tmp);
  101. #endif
  102. #if defined (EACCES)
  103. case EACCES:
  104. throw EaccesExc (tmp);
  105. #endif
  106. #if defined (EFAULT)
  107. case EFAULT:
  108. throw EfaultExc (tmp);
  109. #endif
  110. #if defined (ENOTBLK)
  111. case ENOTBLK:
  112. throw EnotblkExc (tmp);
  113. #endif
  114. #if defined (EBUSY)
  115. case EBUSY:
  116. throw EbusyExc (tmp);
  117. #endif
  118. #if defined (EEXIST)
  119. case EEXIST:
  120. throw EexistExc (tmp);
  121. #endif
  122. #if defined (EXDEV)
  123. case EXDEV:
  124. throw ExdevExc (tmp);
  125. #endif
  126. #if defined (ENODEV)
  127. case ENODEV:
  128. throw EnodevExc (tmp);
  129. #endif
  130. #if defined (ENOTDIR)
  131. case ENOTDIR:
  132. throw EnotdirExc (tmp);
  133. #endif
  134. #if defined (EISDIR)
  135. case EISDIR:
  136. throw EisdirExc (tmp);
  137. #endif
  138. #if defined (EINVAL)
  139. case EINVAL:
  140. throw EinvalExc (tmp);
  141. #endif
  142. #if defined (ENFILE)
  143. case ENFILE:
  144. throw EnfileExc (tmp);
  145. #endif
  146. #if defined (EMFILE)
  147. case EMFILE:
  148. throw EmfileExc (tmp);
  149. #endif
  150. #if defined (ENOTTY)
  151. case ENOTTY:
  152. throw EnottyExc (tmp);
  153. #endif
  154. #if defined (ETXTBSY)
  155. case ETXTBSY:
  156. throw EtxtbsyExc (tmp);
  157. #endif
  158. #if defined (EFBIG)
  159. case EFBIG:
  160. throw EfbigExc (tmp);
  161. #endif
  162. #if defined (ENOSPC)
  163. case ENOSPC:
  164. throw EnospcExc (tmp);
  165. #endif
  166. #if defined (ESPIPE)
  167. case ESPIPE:
  168. throw EspipeExc (tmp);
  169. #endif
  170. #if defined (EROFS)
  171. case EROFS:
  172. throw ErofsExc (tmp);
  173. #endif
  174. #if defined (EMLINK)
  175. case EMLINK:
  176. throw EmlinkExc (tmp);
  177. #endif
  178. #if defined (EPIPE)
  179. case EPIPE:
  180. throw EpipeExc (tmp);
  181. #endif
  182. #if defined (EDOM)
  183. case EDOM:
  184. throw EdomExc (tmp);
  185. #endif
  186. #if defined (ERANGE)
  187. case ERANGE:
  188. throw ErangeExc (tmp);
  189. #endif
  190. #if defined (ENOMSG)
  191. case ENOMSG:
  192. throw EnomsgExc (tmp);
  193. #endif
  194. #if defined (EIDRM)
  195. case EIDRM:
  196. throw EidrmExc (tmp);
  197. #endif
  198. #if defined (ECHRNG)
  199. case ECHRNG:
  200. throw EchrngExc (tmp);
  201. #endif
  202. #if defined (EL2NSYNC)
  203. case EL2NSYNC:
  204. throw El2nsyncExc (tmp);
  205. #endif
  206. #if defined (EL3HLT)
  207. case EL3HLT:
  208. throw El3hltExc (tmp);
  209. #endif
  210. #if defined (EL3RST)
  211. case EL3RST:
  212. throw El3rstExc (tmp);
  213. #endif
  214. #if defined (ELNRNG)
  215. case ELNRNG:
  216. throw ElnrngExc (tmp);
  217. #endif
  218. #if defined (EUNATCH)
  219. case EUNATCH:
  220. throw EunatchExc (tmp);
  221. #endif
  222. #if defined (ENOSCI)
  223. case ENOCSI:
  224. throw EnocsiExc (tmp);
  225. #endif
  226. #if defined (EL2HLT)
  227. case EL2HLT:
  228. throw El2hltExc (tmp);
  229. #endif
  230. #if defined (EDEADLK)
  231. case EDEADLK:
  232. throw EdeadlkExc (tmp);
  233. #endif
  234. #if defined (ENOLCK)
  235. case ENOLCK:
  236. throw EnolckExc (tmp);
  237. #endif
  238. #if defined (EBADE)
  239. case EBADE:
  240. throw EbadeExc (tmp);
  241. #endif
  242. #if defined (EBADR)
  243. case EBADR:
  244. throw EbadrExc (tmp);
  245. #endif
  246. #if defined (EXFULL)
  247. case EXFULL:
  248. throw ExfullExc (tmp);
  249. #endif
  250. #if defined (ENOANO)
  251. case ENOANO:
  252. throw EnoanoExc (tmp);
  253. #endif
  254. #if defined (EBADRQC)
  255. case EBADRQC:
  256. throw EbadrqcExc (tmp);
  257. #endif
  258. #if defined (EBADSLT)
  259. case EBADSLT:
  260. throw EbadsltExc (tmp);
  261. #endif
  262. #if defined (EDEADLOCK) && defined (EDEADLK)
  263. #if EDEADLOCK != EDEADLK
  264. case EDEADLOCK:
  265. throw EdeadlockExc (tmp);
  266. #endif
  267. #elif defined (EDEADLOCK)
  268. case EDEADLOCK:
  269. throw EdeadlockExc (tmp);
  270. #endif
  271. #if defined (EBFONT)
  272. case EBFONT:
  273. throw EbfontExc (tmp);
  274. #endif
  275. #if defined (ENOSTR)
  276. case ENOSTR:
  277. throw EnostrExc (tmp);
  278. #endif
  279. #if defined (ENODATA)
  280. case ENODATA:
  281. throw EnodataExc (tmp);
  282. #endif
  283. #if defined (ETIME)
  284. case ETIME:
  285. throw EtimeExc (tmp);
  286. #endif
  287. #if defined (ENOSR)
  288. case ENOSR:
  289. throw EnosrExc (tmp);
  290. #endif
  291. #if defined (ENONET)
  292. case ENONET:
  293. throw EnonetExc (tmp);
  294. #endif
  295. #if defined (ENOPKG)
  296. case ENOPKG:
  297. throw EnopkgExc (tmp);
  298. #endif
  299. #if defined (EREMOTE)
  300. case EREMOTE:
  301. throw EremoteExc (tmp);
  302. #endif
  303. #if defined (ENOLINK)
  304. case ENOLINK:
  305. throw EnolinkExc (tmp);
  306. #endif
  307. #if defined (EADV)
  308. case EADV:
  309. throw EadvExc (tmp);
  310. #endif
  311. #if defined (ESRMNT)
  312. case ESRMNT:
  313. throw EsrmntExc (tmp);
  314. #endif
  315. #if defined (ECOMM)
  316. case ECOMM:
  317. throw EcommExc (tmp);
  318. #endif
  319. #if defined (EPROTO)
  320. case EPROTO:
  321. throw EprotoExc (tmp);
  322. #endif
  323. #if defined (EMULTIHOP)
  324. case EMULTIHOP:
  325. throw EmultihopExc (tmp);
  326. #endif
  327. #if defined (EBADMSG)
  328. case EBADMSG:
  329. throw EbadmsgExc (tmp);
  330. #endif
  331. #if defined (ENAMETOOLONG)
  332. case ENAMETOOLONG:
  333. throw EnametoolongExc (tmp);
  334. #endif
  335. #if defined (EOVERFLOW)
  336. case EOVERFLOW:
  337. throw EoverflowExc (tmp);
  338. #endif
  339. #if defined (ENOTUNIQ)
  340. case ENOTUNIQ:
  341. throw EnotuniqExc (tmp);
  342. #endif
  343. #if defined (EBADFD)
  344. case EBADFD:
  345. throw EbadfdExc (tmp);
  346. #endif
  347. #if defined (EREMCHG)
  348. case EREMCHG:
  349. throw EremchgExc (tmp);
  350. #endif
  351. #if defined (ELIBACC)
  352. case ELIBACC:
  353. throw ElibaccExc (tmp);
  354. #endif
  355. #if defined (ELIBBAD)
  356. case ELIBBAD:
  357. throw ElibbadExc (tmp);
  358. #endif
  359. #if defined (ELIBSCN)
  360. case ELIBSCN:
  361. throw ElibscnExc (tmp);
  362. #endif
  363. #if defined (ELIBMAX)
  364. case ELIBMAX:
  365. throw ElibmaxExc (tmp);
  366. #endif
  367. #if defined (ELIBEXEC)
  368. case ELIBEXEC:
  369. throw ElibexecExc (tmp);
  370. #endif
  371. #if defined (EILSEQ)
  372. case EILSEQ:
  373. throw EilseqExc (tmp);
  374. #endif
  375. #if defined (ENOSYS)
  376. case ENOSYS:
  377. throw EnosysExc (tmp);
  378. #endif
  379. #if defined (ELOOP)
  380. case ELOOP:
  381. throw EloopExc (tmp);
  382. #endif
  383. #if defined (ERESTART)
  384. case ERESTART:
  385. throw ErestartExc (tmp);
  386. #endif
  387. #if defined (ESTRPIPE)
  388. case ESTRPIPE:
  389. throw EstrpipeExc (tmp);
  390. #endif
  391. #if defined (ENOTEMPTY)
  392. case ENOTEMPTY:
  393. throw EnotemptyExc (tmp);
  394. #endif
  395. #if defined (EUSERS)
  396. case EUSERS:
  397. throw EusersExc (tmp);
  398. #endif
  399. #if defined (ENOTSOCK)
  400. case ENOTSOCK:
  401. throw EnotsockExc (tmp);
  402. #endif
  403. #if defined (EDESTADDRREQ)
  404. case EDESTADDRREQ:
  405. throw EdestaddrreqExc (tmp);
  406. #endif
  407. #if defined (EMSGSIZE)
  408. case EMSGSIZE:
  409. throw EmsgsizeExc (tmp);
  410. #endif
  411. #if defined (EPROTOTYPE)
  412. case EPROTOTYPE:
  413. throw EprototypeExc (tmp);
  414. #endif
  415. #if defined (ENOPROTOOPT)
  416. case ENOPROTOOPT:
  417. throw EnoprotooptExc (tmp);
  418. #endif
  419. #if defined (EPROTONOSUPPORT)
  420. case EPROTONOSUPPORT:
  421. throw EprotonosupportExc (tmp);
  422. #endif
  423. #if defined (ESOCKTNOSUPPORT)
  424. case ESOCKTNOSUPPORT:
  425. throw EsocktnosupportExc (tmp);
  426. #endif
  427. #if defined (EOPNOTSUPP)
  428. case EOPNOTSUPP:
  429. throw EopnotsuppExc (tmp);
  430. #endif
  431. #if defined (EPFNOSUPPORT)
  432. case EPFNOSUPPORT:
  433. throw EpfnosupportExc (tmp);
  434. #endif
  435. #if defined (EAFNOSUPPORT)
  436. case EAFNOSUPPORT:
  437. throw EafnosupportExc (tmp);
  438. #endif
  439. #if defined (EADDRINUSE)
  440. case EADDRINUSE:
  441. throw EaddrinuseExc (tmp);
  442. #endif
  443. #if defined (EADDRNOTAVAIL)
  444. case EADDRNOTAVAIL:
  445. throw EaddrnotavailExc (tmp);
  446. #endif
  447. #if defined (ENETDOWN)
  448. case ENETDOWN:
  449. throw EnetdownExc (tmp);
  450. #endif
  451. #if defined (ENETUNREACH)
  452. case ENETUNREACH:
  453. throw EnetunreachExc (tmp);
  454. #endif
  455. #if defined (ENETRESET)
  456. case ENETRESET:
  457. throw EnetresetExc (tmp);
  458. #endif
  459. #if defined (ECONNABORTED)
  460. case ECONNABORTED:
  461. throw EconnabortedExc (tmp);
  462. #endif
  463. #if defined (ECONNRESET)
  464. case ECONNRESET:
  465. throw EconnresetExc (tmp);
  466. #endif
  467. #if defined (ENOBUFS)
  468. case ENOBUFS:
  469. throw EnobufsExc (tmp);
  470. #endif
  471. #if defined (EISCONN)
  472. case EISCONN:
  473. throw EisconnExc (tmp);
  474. #endif
  475. #if defined (ENOTCONN)
  476. case ENOTCONN:
  477. throw EnotconnExc (tmp);
  478. #endif
  479. #if defined (ESHUTDOWN)
  480. case ESHUTDOWN:
  481. throw EshutdownExc (tmp);
  482. #endif
  483. #if defined (ETOOMANYREFS)
  484. case ETOOMANYREFS:
  485. throw EtoomanyrefsExc (tmp);
  486. #endif
  487. #if defined (ETIMEDOUT)
  488. case ETIMEDOUT:
  489. throw EtimedoutExc (tmp);
  490. #endif
  491. #if defined (ECONNREFUSED)
  492. case ECONNREFUSED:
  493. throw EconnrefusedExc (tmp);
  494. #endif
  495. #if defined (EHOSTDOWN)
  496. case EHOSTDOWN:
  497. throw EhostdownExc (tmp);
  498. #endif
  499. #if defined (EHOSTUNREACH)
  500. case EHOSTUNREACH:
  501. throw EhostunreachExc (tmp);
  502. #endif
  503. #if defined (EALREADY)
  504. case EALREADY:
  505. throw EalreadyExc (tmp);
  506. #endif
  507. #if defined (EINPROGRESS)
  508. case EINPROGRESS:
  509. throw EinprogressExc (tmp);
  510. #endif
  511. #if defined (ESTALE)
  512. case ESTALE:
  513. throw EstaleExc (tmp);
  514. #endif
  515. #if defined (EIORESID)
  516. case EIORESID:
  517. throw EioresidExc (tmp);
  518. #endif
  519. #if defined (EUCLEAN)
  520. case EUCLEAN:
  521. throw EucleanExc (tmp);
  522. #endif
  523. #if defined (ENOTNAM)
  524. case ENOTNAM:
  525. throw EnotnamExc (tmp);
  526. #endif
  527. #if defined (ENAVAIL)
  528. case ENAVAIL:
  529. throw EnavailExc (tmp);
  530. #endif
  531. #if defined (EISNAM)
  532. case EISNAM:
  533. throw EisnamExc (tmp);
  534. #endif
  535. #if defined (EREMOTEIO)
  536. case EREMOTEIO:
  537. throw EremoteioExc (tmp);
  538. #endif
  539. #if defined (EINIT)
  540. case EINIT:
  541. throw EinitExc (tmp);
  542. #endif
  543. #if defined (EREMDEV)
  544. case EREMDEV:
  545. throw EremdevExc (tmp);
  546. #endif
  547. #if defined (ECANCELED)
  548. case ECANCELED:
  549. throw EcanceledExc (tmp);
  550. #endif
  551. #if defined (ENOLIMFILE)
  552. case ENOLIMFILE:
  553. throw EnolimfileExc (tmp);
  554. #endif
  555. #if defined (EPROCLIM)
  556. case EPROCLIM:
  557. throw EproclimExc (tmp);
  558. #endif
  559. #if defined (EDISJOINT)
  560. case EDISJOINT:
  561. throw EdisjointExc (tmp);
  562. #endif
  563. #if defined (ENOLOGIN)
  564. case ENOLOGIN:
  565. throw EnologinExc (tmp);
  566. #endif
  567. #if defined (ELOGINLIM)
  568. case ELOGINLIM:
  569. throw EloginlimExc (tmp);
  570. #endif
  571. #if defined (EGROUPLOOP)
  572. case EGROUPLOOP:
  573. throw EgrouploopExc (tmp);
  574. #endif
  575. #if defined (ENOATTACH)
  576. case ENOATTACH:
  577. throw EnoattachExc (tmp);
  578. #endif
  579. #if defined (ENOTSUP) && defined (EOPNOTSUPP)
  580. #if ENOTSUP != EOPNOTSUPP
  581. case ENOTSUP:
  582. throw EnotsupExc (tmp);
  583. #endif
  584. #elif defined (ENOTSUP)
  585. case ENOTSUP:
  586. throw EnotsupExc (tmp);
  587. #endif
  588. #if defined (ENOATTR)
  589. case ENOATTR:
  590. throw EnoattrExc (tmp);
  591. #endif
  592. #if defined (EDIRCORRUPTED)
  593. case EDIRCORRUPTED:
  594. throw EdircorruptedExc (tmp);
  595. #endif
  596. #if defined (EDQUOT)
  597. case EDQUOT:
  598. throw EdquotExc (tmp);
  599. #endif
  600. #if defined (ENFSREMOTE)
  601. case ENFSREMOTE:
  602. throw EnfsremoteExc (tmp);
  603. #endif
  604. #if defined (ECONTROLLER)
  605. case ECONTROLLER:
  606. throw EcontrollerExc (tmp);
  607. #endif
  608. #if defined (ENOTCONTROLLER)
  609. case ENOTCONTROLLER:
  610. throw EnotcontrollerExc (tmp);
  611. #endif
  612. #if defined (EENQUEUED)
  613. case EENQUEUED:
  614. throw EenqueuedExc (tmp);
  615. #endif
  616. #if defined (ENOTENQUEUED)
  617. case ENOTENQUEUED:
  618. throw EnotenqueuedExc (tmp);
  619. #endif
  620. #if defined (EJOINED)
  621. case EJOINED:
  622. throw EjoinedExc (tmp);
  623. #endif
  624. #if defined (ENOTJOINED)
  625. case ENOTJOINED:
  626. throw EnotjoinedExc (tmp);
  627. #endif
  628. #if defined (ENOPROC)
  629. case ENOPROC:
  630. throw EnoprocExc (tmp);
  631. #endif
  632. #if defined (EMUSTRUN)
  633. case EMUSTRUN:
  634. throw EmustrunExc (tmp);
  635. #endif
  636. #if defined (ENOTSTOPPED)
  637. case ENOTSTOPPED:
  638. throw EnotstoppedExc (tmp);
  639. #endif
  640. #if defined (ECLOCKCPU)
  641. case ECLOCKCPU:
  642. throw EclockcpuExc (tmp);
  643. #endif
  644. #if defined (EINVALSTATE)
  645. case EINVALSTATE:
  646. throw EinvalstateExc (tmp);
  647. #endif
  648. #if defined (ENOEXIST)
  649. case ENOEXIST:
  650. throw EnoexistExc (tmp);
  651. #endif
  652. #if defined (EENDOFMINOR)
  653. case EENDOFMINOR:
  654. throw EendofminorExc (tmp);
  655. #endif
  656. #if defined (EBUFSIZE)
  657. case EBUFSIZE:
  658. throw EbufsizeExc (tmp);
  659. #endif
  660. #if defined (EEMPTY)
  661. case EEMPTY:
  662. throw EemptyExc (tmp);
  663. #endif
  664. #if defined (ENOINTRGROUP)
  665. case ENOINTRGROUP:
  666. throw EnointrgroupExc (tmp);
  667. #endif
  668. #if defined (EINVALMODE)
  669. case EINVALMODE:
  670. throw EinvalmodeExc (tmp);
  671. #endif
  672. #if defined (ECANTEXTENT)
  673. case ECANTEXTENT:
  674. throw EcantextentExc (tmp);
  675. #endif
  676. #if defined (EINVALTIME)
  677. case EINVALTIME:
  678. throw EinvaltimeExc (tmp);
  679. #endif
  680. #if defined (EDESTROYED)
  681. case EDESTROYED:
  682. throw EdestroyedExc (tmp);
  683. #endif
  684. }
  685. throw ErrnoExc (tmp);
  686. }
  687. void throwErrnoExc (const std::string &text)
  688. {
  689. throwErrnoExc (text, errno);
  690. }
  691. } // namespace Iex