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