• Quick Start
  • Booting
  • Platform
  • Portals
  • References
    • API Reference TOI3
    • IIP Reference
  • Resources
ARRIS Enterprises, Inc. Confidential Information

TOI3 Exceptions

Error handling in TOI is done exclusively using exceptions. There are multiple types of exceptions, each signalling a type of error condition. For each method available in TOI, the possible exceptions, if any, are enumerated in the API reference. It is highly advisable to handle these exceptions to avoid erratic application behavior.

Exception types

TOI3/JS exceptions are compatible with the built-in ECMAScript Error type and relate to each other in the following way:

┌──────────────────────────────────┐
│ Error (ECMAScript built-in type) │
└────┬─────────────────────────────┘
┌────┴─────────┐
│ ToiException │
└────┬─────────┘
     ├──────────────────────────────┬───────────────────────────────┬──┄┄┄
┌────┴────────────────────────┐ ┌───┴──────────────────────────┐ ┌──┴──┄┄┄
│ ToiInvalidArgumentException │ │ ToiPermissionDeniedException │ │ ...
└─────────────────────────────┘ └──────────────────────────────┘ └─────┄┄┄

Handling exceptions

Like standard exceptions, all TOI exceptions have name and message properties, as well as the usual toString() implementation:


try {
  toi.informationService.getObject("nonExistingObject");
} catch (exception) {
  alert(exception.name);    // gives "ToiInvalidArgumentException"
  alert(exception.message); // gives "Unknown object nonExistingObject"
  alert(exception);         // gives "ToiInvalidArgumentException: Unknown object nonExistingObject"
}

The type of exception caught can be determined using the instanceof operator, like so:


try {
  // TOI call
} catch (exception) {
  if (exception instanceof toi.ToiInvalidArgumentException) {
    ...
  } else if (exception instanceof toi.ToiOperationNotSupportedException) {
    ...
  }
  ...
}

It's possible to tell TOI exceptions apart from non-TOI exceptions by checking if the exception is an instanceof the base type toi.ToiException

:

try {
  // TOI call
} catch (exception) {
  if (exception instanceof toi.ToiException) {
    ...
  } else {
    throw exception;
  }
}

A comparison between TOI2/JS and TOI3/JS exceptions

Exceptions in TOI3/JS work slightly different from how they worked in TOI2/JS. They are somewhat easier to use now and work more like how JavaScript programmers expect them to.

Example Comment
TOI2/JS:

try {
  // TOI call
} catch (rawException) {
  var exception = toi.utils.convertToiException(rawException);
  ...
}
TOI3/JS:

try {
  // TOI call
} catch (exception) {
  ...
}
In TOI3/JS, toi.utils.convertToiException has been removed as you get a useful exception object directly.
TOI2/JS:

if (exception instanceof TToiInvalidArgumentException) {
TOI3/JS:

if (exception instanceof toi.ToiInvalidArgumentException) {
Exception types are scoped to the toi object, and they do not have that extra "T" prefix anymore.
TOI2/JS:

if (e.code == 603) {
TOI3/JS:

if (e instanceof toi.ToiInvalidArgumentException) {
or

if (e.name == "ToiInvalidArgumentException") {
Numerical exception identifiers are no longer present. Instead, the instanceof operator can be used to determine the exception type. When there is a need to discriminate between exceptions using some type-unique property, the name property can be used.

5.1.p5

Copyright (c) 2017 ARRIS Enterprises, LLC. All Rights Reserved. ARRIS Enterprises, LLC. Confidential Information.