/src/modules/kino/error.cc

https://github.com/mltframework/mlt · C++ · 103 lines · 57 code · 19 blank · 27 comment · 9 complexity · 8f0952b2e948bee84d14148c6d1e095e MD5 · raw file

  1. /*
  2. * error.cc Error handling
  3. * Copyright (C) 2000 Arne Schirmacher <arne@schirmacher.de>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software Foundation,
  17. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #ifdef HAVE_CONFIG_H
  20. #include <config.h>
  21. #endif
  22. // C++ includes
  23. #include <string>
  24. #include <iostream>
  25. #include <sstream>
  26. #include <iomanip>
  27. using std::ostringstream;
  28. using std::string;
  29. using std::endl;
  30. using std::ends;
  31. using std::cerr;
  32. // C includes
  33. #include <errno.h>
  34. #include <string.h>
  35. // local includes
  36. #include "error.h"
  37. void real_fail_neg( int eval, const char *eval_str, const char *func, const char *file, int line )
  38. {
  39. if ( eval < 0 )
  40. {
  41. string exc;
  42. ostringstream sb;
  43. sb << file << ":" << line << ": In function \"" << func << "\": \"" << eval_str << "\" evaluated to " << eval;
  44. if ( errno != 0 )
  45. sb << endl << file << ":" << line << ": errno: " << errno << " (" << strerror( errno ) << ")";
  46. sb << ends;
  47. exc = sb.str();
  48. cerr << exc << endl;
  49. throw exc;
  50. }
  51. }
  52. /** error handler for NULL result codes
  53. Whenever this is called with a NULL argument, it will throw an
  54. exception. Typically used with functions like malloc() and new().
  55. */
  56. void real_fail_null( const void *eval, const char *eval_str, const char *func, const char *file, int line )
  57. {
  58. if ( eval == NULL )
  59. {
  60. string exc;
  61. ostringstream sb;
  62. sb << file << ":" << line << ": In function \"" << func << "\": " << eval_str << " is NULL" << ends;
  63. exc = sb.str();
  64. cerr << exc << endl;
  65. throw exc;
  66. }
  67. }
  68. void real_fail_if( bool eval, const char *eval_str, const char *func, const char *file, int line )
  69. {
  70. if ( eval == true )
  71. {
  72. string exc;
  73. ostringstream sb;
  74. sb << file << ":" << line << ": In function \"" << func << "\": condition \"" << eval_str << "\" is true";
  75. if ( errno != 0 )
  76. sb << endl << file << ":" << line << ": errno: " << errno << " (" << strerror( errno ) << ")";
  77. sb << ends;
  78. exc = sb.str();
  79. cerr << exc << endl;
  80. throw exc;
  81. }
  82. }