查找

記事
· 2025年2月7日 4m read

IRIS %Status and Exceptions

You may encounter errors during any point of program execution, and there are several ways to raise and handle these exceptions. In this article, we'll explore how exceptions are handled efficiently in IRIS.

One of the most commonly used return types is %Status, which is used by methods to indicate success or failure. Let's begin by discussing %Status values.

Working with %Status

The %Status return type is used to represent errors or success. Many system methods return %Status when an error occurs. You can create a similar structure for your application errors, or convert to %Status, even when you raised exceptions  in your code.

Let's start creating the errors

Macros

When we talked about errors the Macros are essential and easy to create Status values in the code. IRIS provides several macros to create and handle errors within your application code.

The most commonly used macro is $$$ERROR.

$$$ERROR

The $$$ERROR macro specifically designed to generate and return a %Library.%Status value. It is your responsibility to check the status before continuing execution in your program. This macro is tightly coupled with general system errors. Keep the following points in mind when using this macro:

- The first argument (error codes) refers to general error codes inside the %occErrors include file.
- If you're using predefined errors from that include file, you can use the macro directly, with or without additional arguments.

Note: Before proceeding $SYSTEM.OBJ.DisplayError(status) or $SYSTEM.Status.DisplayError(status) used to display the error(s) and supports string localization 

Set sc = $$$ERROR($$$NamespaceDoesNotExist,"TEST")
Do $SYSTEM.OBJ.DisplayError(sc)

output: ERROR #5015: Namespace 'TEST' does not exist1
Set sc = $$$ERROR($$$UserCTRLC)
Do $SYSTEM.OBJ.DisplayError(sc)

ouput: ERROR #834: Login aborted1

If you use any other error code not listed in %occErrors, an "Unknown status code" error will be returned. Always use the predefined errorcode $$$GeneralError == 5001 for general error messages.

Unknown status code sample

Set sc = $$$ERROR(95875,"TEST Error")
Do $SYSTEM.Status.DisplayError(sc)

output: ERROR #95875: Unknown status code: 95875 (TEST Error)
Set sc = $$$ERROR($$$GeneralError,"TEST Error")
Do $SYSTEM.OBJ.DisplayError(sc)

output: ERROR #5001: TEST Error

$$$ADDSC

The %Status doesn't necessarily hold only one error. Your program can validate multiple conditions and keep track of all errors in a single status, then use the $$$ADDSC macro. For example, the %ValidateObject() method can return multiple errors in a single response, which uses this functionality.

The $$$ADDSC macro appends one status to another, and the $SYSTEM.Status.AppendStatus method performs the same function.

$$$ADDSC(sc1,sc2) / $SYSTEM.Status.AppendStatus(s1,s2) - append sc2 to sc1 and return a new status code.

ClassMethod AppendErrors()
{
    Set sc1 = $$$ERROR($$$UserCTRLC) 
    Set sc2 = $$$ERROR($$$NamespaceDoesNotExist,"TEST")
    Set sc = $$$ADDSC(sc1,sc2)
    Do $SYSTEM.Status.DisplayError(sc)
    Write !
    Set sc = $$$ADDSC(sc1,sc2)
    Do $SYSTEM.Status.DisplayError(sc)
}
output
LEARNING>do ##class(Learning.ErrorHandling).AppendErrors()
 
ERROR #834: Login aborted
ERROR #5015: Namespace 'TEST' does not exist
 
ERROR #834: Login aborted
ERROR #5015: Namespace 'TEST' does not exist

both results are same!

$$$GETERRORCODE

$$$GETERRORCODE(status) - Returns the error code value from the Status . This macro is belongs from the %occStatus.inc

    Set status = $$$ERROR($$$UserCTRLC) 
    Write $$$GETERRORCODE(status),!
    #;output: 834
    Set status = $$$ERROR($$$GeneralError,"TEST Error")
    Write $$$GETERRORCODE(status)
    #;output: 5001

$$$GETERRORMESSAGE
$$$GETERRORMESSAGE(sc,num) - This macro is returns the portion of the error based on the num in the %Status 
Here is an example.
 

ClassMethod GetErrorMsgMacro()
{
	Set status = $$$ERROR($$$GeneralError,"TEST Error",1,$$$ERROR($$$GeneralError,"TEST Error2"))
	write $$$GETERRORMESSAGE(status),! ; It prints "TEST Error"
	#;
	Set st = $$$GETERRORMESSAGE(status,3) ; it get the "$$$ERROR($$$GeneralError,"TEST Error2")" in 3rd position based on the 2nd argument 
	write $$$GETERRORMESSAGE(st),! ; it prints TEST Error2
}

LEARNING>Do ##class(Learning.myexcept).GetErrorMsgMacro()
TEST Error
TEST Error2

 

Validate Return Status

Now that you've created the error and returned it to your program, the next step is validating whether the return response is successful or erroneous.

The $$$ISERR macro checks whether the status represents an error. It returns 1 if the status indicates an error, otherwise it returns 0. There's another macro, $$$ISOK, which returns 1 when the status is successful.

Displaying Errors

If your program unexpectedly errors out (always expect the unexpected), you need to display the error message. The %SYSTEM.Status class is specifically designed for viewing or creating %Status values (if you prefer not to use macros) and we already seen the samples above.

Here are equivalent methods in %SYSTEM.Status that replace the macros:

Macro Methods
$$$ISERR $SYSTEM.Status.IsError()
$$$ISOK $SYSTEM.Status.IsOK()
$$$ADDSC $SYSTEM.Status.AppendStatus()
$$$ERROR $SYSTEM.Status.Error()
$$$OK $SYSTEM.Status.OK()
$$$GETERRORCODE $SYSTEM.Status.GetErrorCodes()

The Exceptions will be continued in the next article.

ディスカッション (0)1
続けるにはログインするか新規登録を行ってください
記事
· 2025年2月7日 1m read

QuinielaML - Predicción de la 41ª jornada de la Quiniela

Venga que nos vamos acercando ya en aciertos, veamos que tal se da esta 41ª jornada de la Quiniela, con partidos de la jornada 23ª de Primera División y 26ª de Segunda.

Veamos los partidos que entran en esta Quiniela:

Con pleno al 15 del derby madrileño por excelencia.

Aquí están las predicciones de Primera División:

Y las de Segunda:

Dándonos la siguiente Quiniela:

¡Suerte y buen fin de semana a todos!

ディスカッション (0)1
続けるにはログインするか新規登録を行ってください
記事
· 2025年2月7日 9m read

IRIS et Presto pour des requêtes SQL performantes et évolutives

L'essor des projets Big Data, des analyses en libre-service en temps réel, des services de recherche en ligne et des réseaux sociaux, entre autres, a donné naissance à des scénarios de requête de données massives et très performantes. En réponse à ce défi, la technologie MPP (base de données de traitement hautement parallèle) a été créée et s'est rapidement imposée. Parmi les options MPP open-source, Presto (https://prestodb.io/) est la plus connue.

ディスカッション (0)0
続けるにはログインするか新規登録を行ってください
記事
· 2025年2月6日 3m read

第十六章 L - M 开头的术语

第十六章 L - M 开头的术语

锁表 (lock table)

系统

IRIS 内部的表,存储所有由进程发出的 LOCK 命令。你可以使用系统查看器查看此表。

日志文件 (log files)

系统

系统管理员目录中的文件,包含关于系统操作、错误和指标的消息。这些包括消息日志(messages.log)、系统监视器日志(SystemMonitor.log)、警报日志(alerts.log)、初始化日志(iboot.log)和日志历史记录日志(journal.log)。有关这些日志文件的信息,请参见“监控日志文件”。

逻辑格式 (logical format)

对象(Objects)

对象属性的逻辑格式是在内存中使用的格式。所有的比较和计算都是基于这种格式进行的。

ディスカッション (0)1
続けるにはログインするか新規登録を行ってください
質問
· 2025年2月6日

RTF replace string logic corrupting document for viewer

I have an MDM interface with a DTL that takes OBX:5 and replaces "{\E\rtf" with "{\rtf" and "\X0A\" with nothing.  Most rtf's this works without a problem, some others, it corrupts the document.  

Code:

<assign value='..ReplaceStr(..ReplaceStr(source.{OBXgrp(k1).OBX:ObservationValue(1)},"{\E\rtf","{\rtf"),"\X0A\","")' property='target.{OBXgrp(k1).OBX:ObservationValue(1)}' disabled = '0' action='set' />

 

My question is - anyone know of any other "gotchas" that could possibly need to be replaced or something?

I have tried not doing the replace on anything, and the document shows up in viewer as just the rtf code rather a human readable document.  I am at a loss, any direction would be wonderful.

Thanks!

1 Comment
ディスカッション (1)1
続けるにはログインするか新規登録を行ってください