MuException.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "mupdf/fitz.h"
  2. #include "../Context.h"
  3. #ifndef __MUEXCEPTION
  4. #define __MUEXCEPTION
  5. #define MuTryReturn(ctx, op, var) var = NULL; fz_try(ctx) { var = op; } fz_catch(ctx) { } return var;
  6. #define MuTry(ctx, op) fz_try(ctx) { op; } fz_catch(ctx) { return 0; } return 1;
  7. #pragma once
  8. using namespace System;
  9. namespace MuPDF {
  10. public ref class MuException : ApplicationException {
  11. public:
  12. MuException() : ApplicationException(), _code(-1) {}
  13. MuException(String^ message) : ApplicationException(message), _code(-1) {};
  14. MuException(String^ message, Exception^ innerException) : ApplicationException(message, innerException), _code(-1) {};
  15. property int Code {
  16. int get() {
  17. return _code;
  18. }
  19. internal: void set(int code) {
  20. _code = code;
  21. }
  22. }
  23. internal:
  24. MuException(const char* message, int code) : ApplicationException(gcnew String(message)), _code(code) {};
  25. static MuException^ FromContext() {
  26. int code;
  27. const char* msg = fz_convert_error(Context::Ptr, &code);
  28. return gcnew MuException(msg, code);
  29. }
  30. private:
  31. int _code;
  32. };
  33. };
  34. #endif // !__MUEXCEPTION