forked from ARSBlue/ToolBox-4-Iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatus.inc
50 lines (43 loc) · 2.98 KB
/
Status.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
ROUTINE arsblue.Status [Type=INC]
/// This include extends the functionality of %occStatus and contains macros for working with status
///
/// ARSBlue ToolBox-4-Iris
/// Copyright © 2019 ARS Blue GmbH
/// http://www.ars-blue.at
/// check for status
#define ISSTATUS(%val) $S(%val=$$$OK:$$$YES,(($L(%val)>2)&&($E(%val,1,2)="0 ")&&($LV($E(%val,3,*)))):$$$YES,1:$$$NO)
/// warning is a special kind of status with an errorcode of zero and a warning message
#define WARNING(%msg) $$$ERROR(0,%msg)
#define ISWARNING(%sc) ($$$ISERR(%sc)&&('$System.Status.GetErrorCodes(%sc)))
#define GETWARNING(%sc) $LG($LG($E(%sc,3,*),1),2)
/// quit with status macros
#define Quit(%sc) quit:$$$ISERR(%sc) %sc
/// %occStatus.inc: #define QuitOnError(%expr) Set sc=%expr Quit:$$$ISERR(sc) sc
/// %occStatus.inc: #define QUITONERROR(%sc,%expr) Set %sc=%expr Quit:$$$ISERR(%sc) %sc
#define QuitIf(%expr,%msg) quit:(%expr) $$$ERROR($$$GeneralError,%msg)
#define QuitOnSQLError(%rs,%rssql) set %rs=%rssql quit:(%rs.%SQLCODE<0) $$$ERROR($$$SQLError,%rs.%Message)
#define QuitError(%msg) quit $$$ERROR($$$GeneralError,%msg)
/// throw status exception macros
#define Throw(%sc) throw:$$$ISERR(%sc) ##class(%Exception.StatusException).ThrowIfInterrupt(%sc)
/// %occStatus.inc: #define ThrowOnError(%expr) Set sc=%expr Throw:$$$ISERR(sc) ##class(%Exception.StatusException).ThrowIfInterrupt(sc)
/// %occStatus.inc: #define THROWONERROR(%sc,%expr) Set %sc=%expr Throw:$$$ISERR(%sc) ##class(%Exception.StatusException).ThrowIfInterrupt(%sc)
#define ThrowIf(%expr,%msg) throw:(%expr) ##class(%Exception.StatusException).ThrowIfInterrupt($$$ERROR($$$GeneralError,%msg))
#define ThrowOnSQLError(%rs,%rssql) set %rs=%rssql throw:(%rs.%SQLCODE<0) ##class(%Exception.StatusException).ThrowIfInterrupt($$$ERROR($$$SQLError,%rs.%Message))
#define ThrowError(%msg) throw ##class(%Exception.StatusException).ThrowIfInterrupt($$$ERROR($$$GeneralError,%msg))
/// return with status macros
#define Return(%sc) return:$$$ISERR(%sc) %sc
#define ReturnOnError(%expr) set sc=%expr return:$$$ISERR(sc) sc
#define RETURNONERROR(%sc,%expr) set %sc=%expr return:$$$ISERR(%sc) %sc
#define ReturnIf(%expr,%msg) return:(%expr) $$$ERROR($$$GeneralError,%msg)
#define ReturnOnSQLError(%rs,%rssql) set %rs=%rssql return:(%rs.%SQLCODE<0) $$$ERROR($$$SQLError,%rs.%Message)
#define ReturnError(%msg) return $$$ERROR($$$GeneralError,%msg)
/// quit on expression macros
#define Break(%expr) quit:(%expr)
#define BreakOnError(%expr) $$$Break($$$ISERR(%expr))
#define BREAKONERROR(%sc,%expr) set %sc=%expr $$$Break($$$ISERR(%sc))
#define BreakOnSQLError(%rs,%rssql) set %rs=%rssql $$$Break(%rs.%SQLCODE<0)
/// continue on expression macros
#define Continue(%expr) continue:(%expr)
#define ContinueOnError(%expr) $$$Continue($$$ISERR(%expr))
#define CONTINUEONERROR(%sc,%expr) set %sc=%expr $$$Continue($$$ISERR(%sc))
#define ContinueOnSQLError(%rs,%rssql) set %rs=%rssql $$$Continue(%rs.%SQLCODE<0)