Try OpenEdge Now
skip to main content
Error Handling
Raising errors with THROW : THROW with user-defined functions : Throwing application errors
 

Throwing application errors

Throwing application errors is a little different. In the first example, you provide a constructor on the UNDO statement to instantiate the AppError. In the caller, you retrieve the error message from the ReturnValue property of the AppError object, as shown:
/* First technique for returning an application error from a
user-defined function. */

DEFINE VARIABLE FuncReturn AS LOGICAL NO-UNDO.

FUNCTION ReturnAppError RETURNS LOGICAL:

FIND FIRST Customer WHERE CustNum = 1000.
RETURN TRUE.

CATCH anyError AS Progress.Lang.ProError:
UNDO, THROW
NEW Progress.Lang.AppError("Function ReturnAppError failed.").
END CATCH.

END FUNCTION.

ASSIGN FuncReturn = ReturnAppError().
CATCH myAppError AS Progress.Lang.AppError:
DISPLAY "Error message returned from function: "
myAppError:ReturnValue FORMAT "X(60)".
END CATCH.
In the second example, to return the AppError to a caller using traditional error handling, again you use the NO-ERROR option on the caller. In an AppError object exists and the ReturnValue property is populated, the AVM always makes that value available in the RETURN-VALUE function, as shown:
/* Second technique for returning an application error from a
user-defined function. */

DEFINE VARIABLE FuncReturn AS LOGICAL NO-UNDO.

FUNCTION ReturnAppError RETURNS LOGICAL:

FIND FIRST Customer WHERE CustNum = 1000.
RETURN TRUE.

CATCH anyError AS Progress.Lang.ProError:
UNDO, THROW
NEW Progress.Lang.AppError("Function ReturnAppError failed.").
END CATCH.

END FUNCTION.

ASSIGN FuncReturn = ReturnAppError() NO-ERROR.

IF ERROR-STATUS:ERROR THEN
DISPLAY "Error message returned from function: "
RETURN-VALUE FORMAT "X(60)".