Handling Exceptions

The Attachmate Verastream SDK for Unisys and Airlines uses exceptions to indicate error conditions. All of the SDK exception classes extend java.lang.Exception. This topic provides general information about catching exceptions.

For details on the SDK exception classes, see the Attachmate Verastream SDK for Unisys and Airlines Javadoc and .NET Reference Guides.

It is recommended that you include catch blocks in methods that create SDK objects (as shown in the following examples). Several SDK methods throw exceptions, and some, such as the putString method, throw several exceptions.

Examples of how to code exceptions for each of the supported development environments are provided in the following sections:

Handling Exceptions in Java

The following Java example includes a catch block for each exception thrown by the putString method:

try
{
   String inText = "PASSWORD";
   int inRow = 1;
   int inColumn = 1;
   int numCharsPut = m_ScreenUts.putString (inText, inRow, inColumn );  
}
catch(ProtectedFieldException e)
{
   System.err.println("ProtectedFieldException\n " );
   return;
}
catch(InputInhibitedException e)
{
   System.err.println("InputInhibitedException\n " );
   return;
}
catch(TruncatedException e)
{
   System.err.println("TruncatedException\n " );
   return;
}

Handling Exceptions in ASP

The following ASP (VBScript) example includes a catch block for an exception thrown when opening a host session:

On Error Resume Next
Err.Clear
CatchExceptionError()

Response.Write "<br>Exceptions will fall through the<br>"
Response.Write "code if the On Error Resume Next is<br>"
Response.Write "set, then catch them in the subroutine.<br>"

set SessionObj = CreateObject("SessionLoader.SessionLoader")
set screenObj = SessionObj.requestScreenEx("","", xmlConfig, 0)

Response.Write " Open returns "  & screenObj.Open() & "<br>"
screenObj.waitForCursor 3,18,250
Response.Write "<br>--><br>" & screenObj.getText() & "<br><--<br>"
CatchExceptionError()
screenObj.putString "bogus", 13,37
Response.Write "<br>--><br>" & screenObj.getText() & "<br><--<br>"
screenObj.Close()

CatchExceptionError()
Response.Write "<br>Done<br>"

Sub CatchExceptionError()
   If Err <> 0 Then
      Response.Write "<br>!!! <br>"
      Response.Write "!!! <br>"
      Response.Write "!!!   Exception error number: " & Err.Number & "<br>"
      Response.Write "!!!   Exception description: " & Err.Description & "<br>"
      Response.Write "!!! <br>"
      Response.Write "!!! <br><br>"
   end if
   screenObj.waitHostQuiet 2000,8000
   Err.Clear
End Sub 

Handling Exceptions in Visual C++

The following Visual C++ example includes a catch block for the exception thrown by the waitHostQuiet method:

int inSettleTime = 1000;
int wtTime = 3000;
TRY
{
    this->m_screenObj.waitHostQuiet(inSettleTime, wtTime);
}
CATCH_ALL(e)
{
    AfxMessageBox("TimedOutException " );
    return;
}
END_CATCH_ALL

Handling Exceptions in .NET

The following .NET example includes a catch block for the exception thrown by the waitForString method:

try
{
   // Waits for the specified text to appear anywhere on the screen
   string inText = "LOGON";
   int inRow = 0;
   int inColumn = 0;
   int wTime = 3000;

   screen.waitForString(inText, inRow, inColumn, wtTime);
}
catch (TimedOutException toe)
{
   Console.Write("TimedOutException\n");
}
Related Topics
Common Tasks
SDK Objects Overview
Handling Events
  Footer