Page tree
Skip to end of metadata
Go to start of metadata

Application.Application.onUnhandledError event is a global level error handler for unhandled errors. This event is raised whenever there has been an unhandled JavaScript error, Network error or Dataset error.

This feature will provide benefit for speed up development for multiple error cases in the application.

The base template in the Smartface covers multilanguage error messages, also error logging for the Smartface Enterprise Server / Smartface Cloud Services. This default behavior is customizable.

If the error is handled with try catch block or with the error event(s) of the raising object, Application.onError event is not raised.

The thrown error object is passed as a parameter to the event function. This object is wrapped with type information regarding which type of this error is. This information is accessible with the “type” property of the “e” parameter object.

Error types are:

•    Server Error
•    Size Overflow
•    JavaScript
•    Dataset

The “this” keyword references to the object which raises the event except JavaScript errors. If it is "JavaScript" error (runtime or syntax) “this” keyword references to the global "JavaScript" object. Using “this” keyword also enables accessing the dynamic object if needed.

The properties of the “e” object might different in each error type.

JavaScript Error

When a "JavaScript" exception occurs, such as a case which should be handled with a try catch block or a syntax error, the "JavaScript" Error object is thrown.  The catch block parameter object is used and wrapped and passed to Application.onError method as “e” parameter object. More information about "JavaScript" Error object can be found in "See Also" section of this article.

It should also be taken into account that when there is a "JavaScript" error in the code, it will break the execution of the code. After breaking, the event will be fired. However, the syntax error might break the whole code in JavaScript file.

In order to avoid firing of an event, please wrap those lines of code with in try catch blocks when needed.

The syntax errors can be avoided using the Syntax Check button on the Smartface.

Here is a run-time error for JavaScript:

var x = 4;
x(); // raises javascript error

The event argument has the following properties:

	line : 19, //the line number on file where the error occures
	sourceURL : "Page1.Smartface", // the file name
	stack : "Page1_TextButton2_OnPressed @ Page1.Smartface : 19 : 10", //Function name @ File Line:Column
	type : "Javascript" // The additional information for handling the error type

Server Error

The Server Error is a type of error originated from the use of network objects ( XMLHttpRequest ). It's raised whenever network related error occurs, such as timeout, socket layer problems and server error messages. The network objects have their own onServerError events. In these events, the event argument “e” has the following properties by default.

type: It is “Server Error” as a string, maintaining the same behavior in Application.onError.

responseCode: A number value represents the error code. The values between 1-99 are core level socket errors raised by the internal code; the values greater than 99 are the "http" error codes received from the connected server. More information about response codes can be found on "See Also" section of this article.

message: A user friendly error message coming from core level socket errors or the "http"body message received from server based on the value of "responseCode".

A network object which has the onServerError is defined raises the onServerError of its own. If that event is not bound, the event of Application.onError is raised (Having the onServerError set prevents raising the Application.onError method for that network object) . On both events, the event argument is the same also the “this” keyword references the same network object. In most of the cases, in a project the business level server error codes should be handled in the same manner. Using the Application.onError event lifts the burden of writing different event codes for each network object, also providing special behavior for network object if needed. It also provides option to write separate code for errors if needed.

Network Error

Timeout Error : After running the network object the following event argument can be observed:

	type : "Server Error", // The additional information for handling the error type
	responseCode : 28, // the code from SAS core (Between 1 and 99)
	message : "Timeout was reached" // User friendly message (All English)

Server Status Code Error

Shown as below:

	type : "Server Error", // The additional information for handling the error type
	responseCode : 400, // the code recieved from server (Greater than 99)
	message : "Bad Request" // http body message recieved from server

See Also:

JavaScript Error Object

Response Codes