1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2002-2012, 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
37 //----------------------------------------------------------------
38 //
39 // Exceptions that correspond to "errno" error codes,
40 // and a function to make throwing those exceptions easy.
41 //
42 //----------------------------------------------------------------
43
44 #include "IexThrowErrnoExc.h"
45 #include "IexErrnoExc.h"
46 #include <string.h>
47 #include <errno.h>
48
49 #ifdef PLATFORM_WINDOWS
50 #include <windows.h>
51 #endif
52
53 IEX_INTERNAL_NAMESPACE_SOURCE_ENTER
54
55
throwErrnoExc(const std::string & text,int errnum)56 void throwErrnoExc (const std::string &text, int errnum)
57 {
58 #ifdef PLATFORM_WINDOWS
59 if (0 != getenv("IEXDEBUGTHROW"))
60 DebugBreak();
61 #endif
62
63 const char *entext = strerror (errnum);
64 std::string tmp (text);
65 std::string::size_type pos;
66
67 while (std::string::npos != (pos = tmp.find ("%T")))
68 tmp.replace (pos, 2, entext, strlen (entext));
69
70 switch (errnum)
71 {
72 #if defined (EPERM)
73 case EPERM:
74 throw EpermExc (tmp);
75 #endif
76
77 #if defined (ENOENT)
78 case ENOENT:
79 throw EnoentExc (tmp);
80 #endif
81
82 #if defined (ESRCH)
83 case ESRCH:
84 throw EsrchExc (tmp);
85 #endif
86
87 #if defined (EINTR)
88 case EINTR:
89 throw EintrExc (tmp);
90 #endif
91
92 #if defined (EIO)
93 case EIO:
94 throw EioExc (tmp);
95 #endif
96
97 #if defined (ENXIO)
98 case ENXIO:
99 throw EnxioExc (tmp);
100 #endif
101
102 #if defined (E2BIG)
103 case E2BIG:
104 throw E2bigExc (tmp);
105 #endif
106
107 #if defined (ENOEXEC)
108 case ENOEXEC:
109 throw EnoexecExc (tmp);
110 #endif
111
112 #if defined (EBADF)
113 case EBADF:
114 throw EbadfExc (tmp);
115 #endif
116
117 #if defined (ECHILD)
118 case ECHILD:
119 throw EchildExc (tmp);
120 #endif
121
122 #if defined (EAGAIN)
123 case EAGAIN:
124 throw EagainExc (tmp);
125 #endif
126
127 #if defined (ENOMEM)
128 case ENOMEM:
129 throw EnomemExc (tmp);
130 #endif
131
132 #if defined (EACCES)
133 case EACCES:
134 throw EaccesExc (tmp);
135 #endif
136
137 #if defined (EFAULT)
138 case EFAULT:
139 throw EfaultExc (tmp);
140 #endif
141
142 #if defined (ENOTBLK)
143 case ENOTBLK:
144 throw EnotblkExc (tmp);
145 #endif
146
147 #if defined (EBUSY)
148 case EBUSY:
149 throw EbusyExc (tmp);
150 #endif
151
152 #if defined (EEXIST)
153 case EEXIST:
154 throw EexistExc (tmp);
155 #endif
156
157 #if defined (EXDEV)
158 case EXDEV:
159 throw ExdevExc (tmp);
160 #endif
161
162 #if defined (ENODEV)
163 case ENODEV:
164 throw EnodevExc (tmp);
165 #endif
166
167 #if defined (ENOTDIR)
168 case ENOTDIR:
169 throw EnotdirExc (tmp);
170 #endif
171
172 #if defined (EISDIR)
173 case EISDIR:
174 throw EisdirExc (tmp);
175 #endif
176
177 #if defined (EINVAL)
178 case EINVAL:
179 throw EinvalExc (tmp);
180 #endif
181
182 #if defined (ENFILE)
183 case ENFILE:
184 throw EnfileExc (tmp);
185 #endif
186
187 #if defined (EMFILE)
188 case EMFILE:
189 throw EmfileExc (tmp);
190 #endif
191
192 #if defined (ENOTTY)
193 case ENOTTY:
194 throw EnottyExc (tmp);
195 #endif
196
197 #if defined (ETXTBSY)
198 case ETXTBSY:
199 throw EtxtbsyExc (tmp);
200 #endif
201
202 #if defined (EFBIG)
203 case EFBIG:
204 throw EfbigExc (tmp);
205 #endif
206
207 #if defined (ENOSPC)
208 case ENOSPC:
209 throw EnospcExc (tmp);
210 #endif
211
212 #if defined (ESPIPE)
213 case ESPIPE:
214 throw EspipeExc (tmp);
215 #endif
216
217 #if defined (EROFS)
218 case EROFS:
219 throw ErofsExc (tmp);
220 #endif
221
222 #if defined (EMLINK)
223 case EMLINK:
224 throw EmlinkExc (tmp);
225 #endif
226
227 #if defined (EPIPE)
228 case EPIPE:
229 throw EpipeExc (tmp);
230 #endif
231
232 #if defined (EDOM)
233 case EDOM:
234 throw EdomExc (tmp);
235 #endif
236
237 #if defined (ERANGE)
238 case ERANGE:
239 throw ErangeExc (tmp);
240 #endif
241
242 #if defined (ENOMSG)
243 case ENOMSG:
244 throw EnomsgExc (tmp);
245 #endif
246
247 #if defined (EIDRM)
248 case EIDRM:
249 throw EidrmExc (tmp);
250 #endif
251
252 #if defined (ECHRNG)
253 case ECHRNG:
254 throw EchrngExc (tmp);
255 #endif
256
257 #if defined (EL2NSYNC)
258 case EL2NSYNC:
259 throw El2nsyncExc (tmp);
260 #endif
261
262 #if defined (EL3HLT)
263 case EL3HLT:
264 throw El3hltExc (tmp);
265 #endif
266
267 #if defined (EL3RST)
268 case EL3RST:
269 throw El3rstExc (tmp);
270 #endif
271
272 #if defined (ELNRNG)
273 case ELNRNG:
274 throw ElnrngExc (tmp);
275 #endif
276
277 #if defined (EUNATCH)
278 case EUNATCH:
279 throw EunatchExc (tmp);
280 #endif
281
282 #if defined (ENOSCI)
283 case ENOCSI:
284 throw EnocsiExc (tmp);
285 #endif
286
287 #if defined (EL2HLT)
288 case EL2HLT:
289 throw El2hltExc (tmp);
290 #endif
291
292 #if defined (EDEADLK)
293 case EDEADLK:
294 throw EdeadlkExc (tmp);
295 #endif
296
297 #if defined (ENOLCK)
298 case ENOLCK:
299 throw EnolckExc (tmp);
300 #endif
301
302 #if defined (EBADE)
303 case EBADE:
304 throw EbadeExc (tmp);
305 #endif
306
307 #if defined (EBADR)
308 case EBADR:
309 throw EbadrExc (tmp);
310 #endif
311
312 #if defined (EXFULL)
313 case EXFULL:
314 throw ExfullExc (tmp);
315 #endif
316
317 #if defined (ENOANO)
318 case ENOANO:
319 throw EnoanoExc (tmp);
320 #endif
321
322 #if defined (EBADRQC)
323 case EBADRQC:
324 throw EbadrqcExc (tmp);
325 #endif
326
327 #if defined (EBADSLT)
328 case EBADSLT:
329 throw EbadsltExc (tmp);
330 #endif
331
332 #if defined (EDEADLOCK) && defined (EDEADLK)
333 #if EDEADLOCK != EDEADLK
334 case EDEADLOCK:
335 throw EdeadlockExc (tmp);
336 #endif
337 #elif defined (EDEADLOCK)
338 case EDEADLOCK:
339 throw EdeadlockExc (tmp);
340 #endif
341
342 #if defined (EBFONT)
343 case EBFONT:
344 throw EbfontExc (tmp);
345 #endif
346
347 #if defined (ENOSTR)
348 case ENOSTR:
349 throw EnostrExc (tmp);
350 #endif
351
352 #if defined (ENODATA)
353 case ENODATA:
354 throw EnodataExc (tmp);
355 #endif
356
357 #if defined (ETIME)
358 case ETIME:
359 throw EtimeExc (tmp);
360 #endif
361
362 #if defined (ENOSR)
363 case ENOSR:
364 throw EnosrExc (tmp);
365 #endif
366
367 #if defined (ENONET)
368 case ENONET:
369 throw EnonetExc (tmp);
370 #endif
371
372 #if defined (ENOPKG)
373 case ENOPKG:
374 throw EnopkgExc (tmp);
375 #endif
376
377 #if defined (EREMOTE)
378 case EREMOTE:
379 throw EremoteExc (tmp);
380 #endif
381
382 #if defined (ENOLINK)
383 case ENOLINK:
384 throw EnolinkExc (tmp);
385 #endif
386
387 #if defined (EADV)
388 case EADV:
389 throw EadvExc (tmp);
390 #endif
391
392 #if defined (ESRMNT)
393 case ESRMNT:
394 throw EsrmntExc (tmp);
395 #endif
396
397 #if defined (ECOMM)
398 case ECOMM:
399 throw EcommExc (tmp);
400 #endif
401
402 #if defined (EPROTO)
403 case EPROTO:
404 throw EprotoExc (tmp);
405 #endif
406
407 #if defined (EMULTIHOP)
408 case EMULTIHOP:
409 throw EmultihopExc (tmp);
410 #endif
411
412 #if defined (EBADMSG)
413 case EBADMSG:
414 throw EbadmsgExc (tmp);
415 #endif
416
417 #if defined (ENAMETOOLONG)
418 case ENAMETOOLONG:
419 throw EnametoolongExc (tmp);
420 #endif
421
422 #if defined (EOVERFLOW)
423 case EOVERFLOW:
424 throw EoverflowExc (tmp);
425 #endif
426
427 #if defined (ENOTUNIQ)
428 case ENOTUNIQ:
429 throw EnotuniqExc (tmp);
430 #endif
431
432 #if defined (EBADFD)
433 case EBADFD:
434 throw EbadfdExc (tmp);
435 #endif
436
437 #if defined (EREMCHG)
438 case EREMCHG:
439 throw EremchgExc (tmp);
440 #endif
441
442 #if defined (ELIBACC)
443 case ELIBACC:
444 throw ElibaccExc (tmp);
445 #endif
446
447 #if defined (ELIBBAD)
448 case ELIBBAD:
449 throw ElibbadExc (tmp);
450 #endif
451
452 #if defined (ELIBSCN)
453 case ELIBSCN:
454 throw ElibscnExc (tmp);
455 #endif
456
457 #if defined (ELIBMAX)
458 case ELIBMAX:
459 throw ElibmaxExc (tmp);
460 #endif
461
462 #if defined (ELIBEXEC)
463 case ELIBEXEC:
464 throw ElibexecExc (tmp);
465 #endif
466
467 #if defined (EILSEQ)
468 case EILSEQ:
469 throw EilseqExc (tmp);
470 #endif
471
472 #if defined (ENOSYS)
473 case ENOSYS:
474 throw EnosysExc (tmp);
475 #endif
476
477 #if defined (ELOOP)
478 case ELOOP:
479 throw EloopExc (tmp);
480 #endif
481
482 #if defined (ERESTART)
483 case ERESTART:
484 throw ErestartExc (tmp);
485 #endif
486
487 #if defined (ESTRPIPE)
488 case ESTRPIPE:
489 throw EstrpipeExc (tmp);
490 #endif
491
492 #if defined (ENOTEMPTY)
493 case ENOTEMPTY:
494 throw EnotemptyExc (tmp);
495 #endif
496
497 #if defined (EUSERS)
498 case EUSERS:
499 throw EusersExc (tmp);
500 #endif
501
502 #if defined (ENOTSOCK)
503 case ENOTSOCK:
504 throw EnotsockExc (tmp);
505 #endif
506
507 #if defined (EDESTADDRREQ)
508 case EDESTADDRREQ:
509 throw EdestaddrreqExc (tmp);
510 #endif
511
512 #if defined (EMSGSIZE)
513 case EMSGSIZE:
514 throw EmsgsizeExc (tmp);
515 #endif
516
517 #if defined (EPROTOTYPE)
518 case EPROTOTYPE:
519 throw EprototypeExc (tmp);
520 #endif
521
522 #if defined (ENOPROTOOPT)
523 case ENOPROTOOPT:
524 throw EnoprotooptExc (tmp);
525 #endif
526
527 #if defined (EPROTONOSUPPORT)
528 case EPROTONOSUPPORT:
529 throw EprotonosupportExc (tmp);
530 #endif
531
532 #if defined (ESOCKTNOSUPPORT)
533 case ESOCKTNOSUPPORT:
534 throw EsocktnosupportExc (tmp);
535 #endif
536
537 #if defined (EOPNOTSUPP)
538 case EOPNOTSUPP:
539 throw EopnotsuppExc (tmp);
540 #endif
541
542 #if defined (EPFNOSUPPORT)
543 case EPFNOSUPPORT:
544 throw EpfnosupportExc (tmp);
545 #endif
546
547 #if defined (EAFNOSUPPORT)
548 case EAFNOSUPPORT:
549 throw EafnosupportExc (tmp);
550 #endif
551
552 #if defined (EADDRINUSE)
553 case EADDRINUSE:
554 throw EaddrinuseExc (tmp);
555 #endif
556
557 #if defined (EADDRNOTAVAIL)
558 case EADDRNOTAVAIL:
559 throw EaddrnotavailExc (tmp);
560 #endif
561
562 #if defined (ENETDOWN)
563 case ENETDOWN:
564 throw EnetdownExc (tmp);
565 #endif
566
567 #if defined (ENETUNREACH)
568 case ENETUNREACH:
569 throw EnetunreachExc (tmp);
570 #endif
571
572 #if defined (ENETRESET)
573 case ENETRESET:
574 throw EnetresetExc (tmp);
575 #endif
576
577 #if defined (ECONNABORTED)
578 case ECONNABORTED:
579 throw EconnabortedExc (tmp);
580 #endif
581
582 #if defined (ECONNRESET)
583 case ECONNRESET:
584 throw EconnresetExc (tmp);
585 #endif
586
587 #if defined (ENOBUFS)
588 case ENOBUFS:
589 throw EnobufsExc (tmp);
590 #endif
591
592 #if defined (EISCONN)
593 case EISCONN:
594 throw EisconnExc (tmp);
595 #endif
596
597 #if defined (ENOTCONN)
598 case ENOTCONN:
599 throw EnotconnExc (tmp);
600 #endif
601
602 #if defined (ESHUTDOWN)
603 case ESHUTDOWN:
604 throw EshutdownExc (tmp);
605 #endif
606
607 #if defined (ETOOMANYREFS)
608 case ETOOMANYREFS:
609 throw EtoomanyrefsExc (tmp);
610 #endif
611
612 #if defined (ETIMEDOUT)
613 case ETIMEDOUT:
614 throw EtimedoutExc (tmp);
615 #endif
616
617 #if defined (ECONNREFUSED)
618 case ECONNREFUSED:
619 throw EconnrefusedExc (tmp);
620 #endif
621
622 #if defined (EHOSTDOWN)
623 case EHOSTDOWN:
624 throw EhostdownExc (tmp);
625 #endif
626
627 #if defined (EHOSTUNREACH)
628 case EHOSTUNREACH:
629 throw EhostunreachExc (tmp);
630 #endif
631
632 #if defined (EALREADY)
633 case EALREADY:
634 throw EalreadyExc (tmp);
635 #endif
636
637 #if defined (EINPROGRESS)
638 case EINPROGRESS:
639 throw EinprogressExc (tmp);
640 #endif
641
642 #if defined (ESTALE)
643 case ESTALE:
644 throw EstaleExc (tmp);
645 #endif
646
647 #if defined (EIORESID)
648 case EIORESID:
649 throw EioresidExc (tmp);
650 #endif
651
652 #if defined (EUCLEAN)
653 case EUCLEAN:
654 throw EucleanExc (tmp);
655 #endif
656
657 #if defined (ENOTNAM)
658 case ENOTNAM:
659 throw EnotnamExc (tmp);
660 #endif
661
662 #if defined (ENAVAIL)
663 case ENAVAIL:
664 throw EnavailExc (tmp);
665 #endif
666
667 #if defined (EISNAM)
668 case EISNAM:
669 throw EisnamExc (tmp);
670 #endif
671
672 #if defined (EREMOTEIO)
673 case EREMOTEIO:
674 throw EremoteioExc (tmp);
675 #endif
676
677 #if defined (EINIT)
678 case EINIT:
679 throw EinitExc (tmp);
680 #endif
681
682 #if defined (EREMDEV)
683 case EREMDEV:
684 throw EremdevExc (tmp);
685 #endif
686
687 #if defined (ECANCELED)
688 case ECANCELED:
689 throw EcanceledExc (tmp);
690 #endif
691
692 #if defined (ENOLIMFILE)
693 case ENOLIMFILE:
694 throw EnolimfileExc (tmp);
695 #endif
696
697 #if defined (EPROCLIM)
698 case EPROCLIM:
699 throw EproclimExc (tmp);
700 #endif
701
702 #if defined (EDISJOINT)
703 case EDISJOINT:
704 throw EdisjointExc (tmp);
705 #endif
706
707 #if defined (ENOLOGIN)
708 case ENOLOGIN:
709 throw EnologinExc (tmp);
710 #endif
711
712 #if defined (ELOGINLIM)
713 case ELOGINLIM:
714 throw EloginlimExc (tmp);
715 #endif
716
717 #if defined (EGROUPLOOP)
718 case EGROUPLOOP:
719 throw EgrouploopExc (tmp);
720 #endif
721
722 #if defined (ENOATTACH)
723 case ENOATTACH:
724 throw EnoattachExc (tmp);
725 #endif
726
727 #if defined (ENOTSUP) && defined (EOPNOTSUPP)
728 #if ENOTSUP != EOPNOTSUPP
729 case ENOTSUP:
730 throw EnotsupExc (tmp);
731 #endif
732 #elif defined (ENOTSUP)
733 case ENOTSUP:
734 throw EnotsupExc (tmp);
735 #endif
736
737 #if defined (ENOATTR)
738 case ENOATTR:
739 throw EnoattrExc (tmp);
740 #endif
741
742 #if defined (EDIRCORRUPTED)
743 case EDIRCORRUPTED:
744 throw EdircorruptedExc (tmp);
745 #endif
746
747 #if defined (EDQUOT)
748 case EDQUOT:
749 throw EdquotExc (tmp);
750 #endif
751
752 #if defined (ENFSREMOTE)
753 case ENFSREMOTE:
754 throw EnfsremoteExc (tmp);
755 #endif
756
757 #if defined (ECONTROLLER)
758 case ECONTROLLER:
759 throw EcontrollerExc (tmp);
760 #endif
761
762 #if defined (ENOTCONTROLLER)
763 case ENOTCONTROLLER:
764 throw EnotcontrollerExc (tmp);
765 #endif
766
767 #if defined (EENQUEUED)
768 case EENQUEUED:
769 throw EenqueuedExc (tmp);
770 #endif
771
772 #if defined (ENOTENQUEUED)
773 case ENOTENQUEUED:
774 throw EnotenqueuedExc (tmp);
775 #endif
776
777 #if defined (EJOINED)
778 case EJOINED:
779 throw EjoinedExc (tmp);
780 #endif
781
782 #if defined (ENOTJOINED)
783 case ENOTJOINED:
784 throw EnotjoinedExc (tmp);
785 #endif
786
787 #if defined (ENOPROC)
788 case ENOPROC:
789 throw EnoprocExc (tmp);
790 #endif
791
792 #if defined (EMUSTRUN)
793 case EMUSTRUN:
794 throw EmustrunExc (tmp);
795 #endif
796
797 #if defined (ENOTSTOPPED)
798 case ENOTSTOPPED:
799 throw EnotstoppedExc (tmp);
800 #endif
801
802 #if defined (ECLOCKCPU)
803 case ECLOCKCPU:
804 throw EclockcpuExc (tmp);
805 #endif
806
807 #if defined (EINVALSTATE)
808 case EINVALSTATE:
809 throw EinvalstateExc (tmp);
810 #endif
811
812 #if defined (ENOEXIST)
813 case ENOEXIST:
814 throw EnoexistExc (tmp);
815 #endif
816
817 #if defined (EENDOFMINOR)
818 case EENDOFMINOR:
819 throw EendofminorExc (tmp);
820 #endif
821
822 #if defined (EBUFSIZE)
823 case EBUFSIZE:
824 throw EbufsizeExc (tmp);
825 #endif
826
827 #if defined (EEMPTY)
828 case EEMPTY:
829 throw EemptyExc (tmp);
830 #endif
831
832 #if defined (ENOINTRGROUP)
833 case ENOINTRGROUP:
834 throw EnointrgroupExc (tmp);
835 #endif
836
837 #if defined (EINVALMODE)
838 case EINVALMODE:
839 throw EinvalmodeExc (tmp);
840 #endif
841
842 #if defined (ECANTEXTENT)
843 case ECANTEXTENT:
844 throw EcantextentExc (tmp);
845 #endif
846
847 #if defined (EINVALTIME)
848 case EINVALTIME:
849 throw EinvaltimeExc (tmp);
850 #endif
851
852 #if defined (EDESTROYED)
853 case EDESTROYED:
854 throw EdestroyedExc (tmp);
855 #endif
856 }
857
858 throw ErrnoExc (tmp);
859 }
860
861
throwErrnoExc(const std::string & text)862 void throwErrnoExc (const std::string &text)
863 {
864 throwErrnoExc (text, errno);
865 }
866
throwErrnoExc()867 void throwErrnoExc()
868 {
869 std::string txt = "%T.";
870 throwErrnoExc (txt);
871 }
872
873 IEX_INTERNAL_NAMESPACE_SOURCE_EXIT
874