Checking Exceptions Returned From Teradata Application Classes - Analytics Database - Teradata Vantage

SQL External Routine Programming

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2023-07-11
dita:mapPath
iiv1628111441820.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
B035-1147
lifecycle
latest
Product Category
Teradata Vantageā„¢

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.