An exception is an event which is performed during the execution of a programm that interrupt the normal flow of instructions.
Personalized messages can be generated through this sentence. In the case of use the attributes, there will be the option of passing parameters to the message or using cataloged language messages.
1 exception
<exception
code='code'
message='message'
type='type'
>
<arg> *
<var /> *
</arg>
</exception>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Acode | string | Identifier of the exception. | |||
Amessage | string | If the code has been inserted, the message of the exception should be here. | |||
Atype | string | Type of exception. It is a free field which if it is informed indicates that this exeption is a user message. If this parameter is informed, when the exception occurs, the stacktrace will not be registered in the trace file but only a simple warning message. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Earg | |||||
Evar | Message parameter. |
Generation of an exception passing a variable in the message.
<xsql-script> <body> <set name='m_customer'>Pedro</set> <exception type='user-exception'>Invalid customer [<m_customer />]</exception> </body> </xsql-script>
A normal exception is performed, but in the log files, instead of a conventional exception with the stack trace where it has occurred, simply it will be registered message of type:
2017-06-08 18:21:09.661 INFO 609 STUDIO [AxionalJettyHttpServerImpl-00000007] deister.webstudio.core.servlet.impl.ServletJSONRequest.handleException(ServletJSONRequest.java:442) - ERROR handling AbstractJSONReq: XSQLScriptException[user-exception:Invalid customer Pedro]
Generation of an exception in differents languages.
<xsql-script> <body> <set name='m_customer'>Lluís Garcia</set> <exception> <lang id='en'>This is an error on Main Script cause: Invalid customer :[<m_customer />]</lang> <lang id='es'>Esto es un error en Main Script causa: Cliente no válido: [<m_customer />]</lang> </exception> </body> </xsql-script>
Generation of an exception passing parameters to the message and the possibility of idiomatize it.
<xsql-script name='exception_args'> <body> <set name='m_customer'>Lluís Garcia</set> <exception code='E001' message='This is an error on {0} cause: {1}'> <arg>Main Script</arg> <arg><string>Invalid customer [<m_customer />]</string></arg> </exception> </body> </xsql-script>
Notas
Through the brackets of the message attribute, the arguments passed to the exception statement are referenced The order of the numbers between brackets will determine the order in which the arguments are passed.
The attributes "code" and "message" will be useful to define idiomatic locations.
2 User Exceptions
Exist situatios in which the programmer needs to interrupt the program and send a message or a notification to the user or to another XSQL Script nested. For it, a very simple mechanism is to generate an exception in the program with the message to report which interrupt the flow of the programm and this exception can be trapped by the clauses <try><catch></catch></try>.
An example of required use of this type of exceptions is performed in the XSQL Scripts. It is used in the RadioFrequency environment because the only possible mechanism to report a error message to the user of the RF terminal is the generation of an exception in the program with the message that you want to report.
However, the use of exceptions for the notification of messages to the user and not for the notification of real program errors, causes the server trace file to be filled with error messages. In those messages, the stack trace appears in the that have occurred and that makes it difficult to distinguish with respect to the exceptions produced by real errors.
To solve this problem, it has been implemented an attribute "type" which can be add to the exception and and that makes it be considered a user exception. In concecuense, it is plotted in the log files or in the console with a simple format in which the indicated exception type is shown and the stack trace of the exception is not shown.
This facilitates the ability to distinguish between a real exception caused by an error (for example an exception produced by an error of SQL syntax) and an exception produced explicitly by the programmer to report an incident to the user.
The format of exception report which can be seen in the console or in the trace file when an user exception is produced is the following:
2017-06-08 18:21:09.661 INFO 609 STUDIO [AxionalJettyHttpServerImpl-00000007] deister.webstudio.core.servlet.impl.ServletJSONRequest.handleException(ServletJSONRequest.java:442) - ERROR handling AbstractJSONReq: XSQLScriptException[user-exception:Invalid customer Pedro]