IexThrowErrnoExc.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Copyright (c) Contributors to the OpenEXR Project.
  4. //
  5. #ifndef INCLUDED_IEXTHROWERRNOEXC_H
  6. #define INCLUDED_IEXTHROWERRNOEXC_H
  7. //----------------------------------------------------------
  8. //
  9. // A function which throws ExcErrno exceptions
  10. //
  11. //----------------------------------------------------------
  12. #include "IexBaseExc.h"
  13. #include "IexExport.h"
  14. IEX_INTERNAL_NAMESPACE_HEADER_ENTER
  15. //--------------------------------------------------------------------------
  16. //
  17. // Function throwErrnoExc() throws an exception which corresponds to
  18. // error code errnum. The exception text is initialized with a copy
  19. // of the string passed to throwErrnoExc(), where all occurrences of
  20. // "%T" have been replaced with the output of strerror(oserror()).
  21. //
  22. // Example:
  23. //
  24. // If opening file /tmp/output failed with an ENOENT error code,
  25. // calling
  26. //
  27. // throwErrnoExc ();
  28. //
  29. // or
  30. //
  31. // throwErrnoExc ("%T.");
  32. //
  33. // will throw an EnoentExc whose text reads
  34. //
  35. // No such file or directory.
  36. //
  37. // More detailed messages can be assembled using stringstreams:
  38. //
  39. // std::stringstream s;
  40. // s << "Cannot open file " << name << " (%T).";
  41. // throwErrnoExc (s);
  42. //
  43. // The resulting exception contains the following text:
  44. //
  45. // Cannot open file /tmp/output (No such file or directory).
  46. //
  47. // Alternatively, you may want to use the THROW_ERRNO macro defined
  48. // in IexMacros.h:
  49. //
  50. // THROW_ERRNO ("Cannot open file " << name << " (%T).")
  51. //
  52. //--------------------------------------------------------------------------
  53. IEX_EXPORT void throwErrnoExc(const std::string &txt, int errnum);
  54. IEX_EXPORT void throwErrnoExc(const std::string &txt);
  55. IEX_EXPORT void throwErrnoExc();
  56. IEX_INTERNAL_NAMESPACE_HEADER_EXIT
  57. #endif // INCLUDED_IEXTHROWERRNOEXC_H