EXCEPT.H
[目次 | 型・クラス・構造体 | マクロ]
1|/***************************************************************************
2|* 1. <<< 例外処理シュミレート (Except) >>>
3|****************************************************************************/
4|
5|#ifndef __EXCEPT_H
6|#define __EXCEPT_H
7|
8|/*----------------------------------------------------------------------
9|[Compone Property]
10|name = Except
11|title = 例外処理
12|category = エラー処理
13|rc = except.c
14|depend =
15|----------------------------------------------------------------------*/
16|
17|#ifndef USES_COMPONE
18|/*[START_OF_COMPONE_HEADER]*/
19|#define USES_EXCEPT
20|/*[END_OF_COMPONE_HEADER]*/
21|#endif /* USES_COMPONE */
22|
23|
24|#include <stdio.h>
25|
26|#define throw( msg ) \
27| { Except_msg = msg; Except_setFileLine(__FILE__,__LINE__); return; }
28|
29|#define throw_r( msg, n ) \
30| { Except_msg = msg; Except_setFileLine(__FILE__,__LINE__); \
31| return n; }
32|
33|#define throws \
34| if ( Except_msg != NULL ) return;
35|
36|#define throws_r(n) \
37| if ( Except_msg != NULL ) return n;
38|
39|#define throw_trys( msg ) \
40| { Except_msg = msg; Except_setFileLine(__FILE__,__LINE__); \
41| goto except; }
42|
43|#define try
44|
45|#define trys \
46| if ( Except_msg != NULL ) goto except;
47|
48|#define catch(msg) \
49| goto except_end; { void* msg; \
50| except: msg = Except_msg; Except_msg = NULL;
51|
52|#define catch_end \
53| } except_end:;
54|
55|
56|/*-------------*/
57|
58|typedef enum Except_id { Except_idBase, Except_idStd }
59| Except_Id;
60|
61|/*--- Except_Base 型 例外 -----------------------------------------*/
62|
63|void Except_print( void* this );
64|
65|/* protected */
66|extern void* Except_msg;
67|typedef struct except_Base {
68| Except_Id type;
69|} Except_Base;
70|
71|/* private */
72|void Except_setFileLine( char* file, int line );
73|
74|/*--- Except_Std 型 例外 -----------------------------------------*/
75|
76|void* Except();
77|void* Except_s( char* msg );
78|void* Except_i( int msg );
79|
80|/* private */
81|typedef struct except_Std { /* inherited exceptBase */
82| Except_Id type; /* Except_idStd 固定 */
83| char* str; /* エラー内容 */
84| int arg_type; /* 0=メッセージなし, 1=文字列型, 2=数値型 */
85| char* arg_str; /* 文字列型メッセージ */
86| int arg_num; /* 数値型メッセージ */
87|} Except_Std;
88|extern Except_Std Except_std;
89|void Except_Std_print( void* this );
90|
91|
92|#endif /* __EXCEPT_H */
93|
94|