Exception Handling

Server applications make use of exceptions for error handling. For example, if you try to remove an item from a list to which it does not belong, the exception IlsNotFound will be thrown.

Exceptions thrown by Server are instances of classes that derive from . These classes are defined in the include files except.h and sexcept.h.

As illustrated below with the exception IlsNullPointerDereferencing, Server catches exceptions according to the conventional C++ technique.

try {

   // some code that may throw an exception

}

catch (IlsNullPointerDereferencing exception) {

      // do something

}

catch (IlsException exception) {

      // some other Views Server exception

}

catch (...) {

      // some non-Views Server exception

}

Note that using exceptions requires that you strictly observe a certain number of rules when writing C++ code. Among other things, you have to be careful:

  • Not to throw exceptions while the initialization list of a constructor executes. Should this happen, the constructor might leave the object in an unspecified state, which could be lethal for the application.

  • Not to allocate new objects before an exception is to be thrown, unless you know exactly what you are doing. Since exceptions cause the C++ stack to be rolled back, the application might be unable to access these objects and, hence, to delete them.