1
0

Except.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #ifndef Except_H
  16. #define Except_H
  17. #include "exception/Er.h"
  18. #include "util/Gcc.h"
  19. #include "util/Linker.h"
  20. Linker_require("exception/Except.c")
  21. #define Except_BUFFER_SZ 1024
  22. struct Except;
  23. struct Except
  24. {
  25. struct Except* next;
  26. void (* exception)(char* message, struct Except* handler);
  27. char message[Except_BUFFER_SZ];
  28. };
  29. Gcc_NORETURN
  30. Gcc_PRINTF(4, 5)
  31. void Except__throw(char* file, int line, struct Except* eh, char* format, ...);
  32. #define Except_throw(...) Except__throw(Gcc_SHORT_FILE, Gcc_LINE, __VA_ARGS__)
  33. #define Except_er(eh, expr) (__extension__({ \
  34. struct Er_Ret* ret = (struct Er_Ret*)0; \
  35. __auto_type o = Er_check(&ret, expr); \
  36. if (ret) { Except_throw(eh, "%s", ret->message); } \
  37. o; \
  38. }))
  39. #endif