1#pragma once
 2
 3#include <stdio.h>
 4
 5#include <pw_interfaces.h>
 6#include <pw_task.h>
 7
 8#ifdef __cplusplus
 9extern "C" {
10#endif
11
12PW_STRUCT(_PwExceptionData) {
13    _PwValue status;      // Status with source file and line where exception was raised
14    _PwValue message;     // can be Null if status description is enough
15    _PwValue parent_exc;  // can be Null
16};
17
18PW_STRUCT(PwExceptionCtorArgs) {
19    PwCtorArgs* next;
20    uint16_t type_id;
21
22    PwValuePtr status;      // mandatory
23    PwValuePtr parent_exc;  // optional, can be nullptr
24    char* message;
25    va_list ap;
26};
27
28#define pw_exception(status_initializer, message, ...)  \
29    do {  \
30        PwValue status = status_initializer;  \
31        _pw_set_exception(&status, PwTypeId_Exception, nullptr, message __VA_OPT__(,) __VA_ARGS__);  \
32    } while (false)
33
34void _pw_set_exception(PwValuePtr status, uint16_t type_id, PwCtorArgs* ctor_args, char* message, ...);
35/*
36 * Create exception.
37 * Wrap status of the current task with new exception.
38 */
39
40/*
41 * Helpers
42 */
43[[nodiscard]] bool pw_is_error(PwValuePtr value);
44[[nodiscard]] bool pw_is_eof(PwValuePtr status);
45[[nodiscard]] bool pw_is_errno(PwValuePtr status, int _errno);
46
47#ifdef __cplusplus
48}
49#endif