1//
2// m3_exception.h
3//
4// Created by Steven Massey on 7/5/19.
5// Copyright © 2019 Steven Massey. All rights reserved.
6//
7// some macros to emulate try/catch
8
9#ifndef m3_exception_h
10#define m3_exception_h
11
12#include "m3_config.h"
13
14# if d_m3EnableExceptionBreakpoint
15
16// declared in m3_info.c
17void ExceptionBreakpoint (cstr_t i_exception, cstr_t i_message);
18
19# define EXCEPTION_PRINT(ERROR) ExceptionBreakpoint (ERROR, (__FILE__ ":" M3_STR(__LINE__)))
20
21# else
22# define EXCEPTION_PRINT(...)
23# endif
24
25
26#define _try M3Result result = m3Err_none;
27#define _(TRY) { result = TRY; if (M3_UNLIKELY(result)) { EXCEPTION_PRINT (result); goto _catch; } }
28#define _throw(ERROR) { result = ERROR; EXCEPTION_PRINT (result); goto _catch; }
29#define _throwif(ERROR, COND) if (M3_UNLIKELY(COND)) { _throw(ERROR); }
30
31#define _throwifnull(PTR) _throwif (m3Err_mallocFailed, !(PTR))
32
33#endif // m3_exception_h
34