17.10 - Checking Exceptions Returned From Teradata Application Classes - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1147-171K
Language
English (United States)

Teradata provides several application classes that external routines may need to use. A method defined for a Teradata application class can return Teradata specific errors by throwing an SQLException where the value of the SQLState field is TS000.

Please note that in the case where an SQLState of TS000, a Teradata Specific Condition, there is an associated Teradata specific error code that may be accessed via the getError() method of the SQLException class. As an implementation detail only, these error codes are allocated like normal Teradata error codes and error text.

Here is an example of using the Tbl class and handling an exception:

public static void ExceptionCatch() {
  try {
    int len = Tbl.getScale(); /* Throws an SQLExeception. */
  } catch (SQLException e) {
    if (e.getSQLState().equals("TS000")) { 
      /* Check Teradata exception.*/
      int TeradataCode = e.getErrorCode(); /* Get specific error. */
    }
  }
}

If an external routine does not handle a TS000 SQLException, an SQLSTATE value of 39001 is returned. Here is an example where the getScale() method of the Tbl class returned an exception to a table UDF that did not handle it:

*** Failure 7827 Java SQL Exception SQLSTATE 39001: Invalid SQL state (TS000 [Error 7850]: Tbl.getScale(int) is invalid for the type of column intended).

For details on the error codes that Teradata application classes can return, see Java Application Classes.