BookException という CobolBookReader 内の新しい COBOL JVM クラスを作成し、その内容を下記のコードに置き換えます。
このクラスは、従来の COBOL ファイル処理ステータス・コードを JVM 例外に変換するためにラッパ・プログラムによって使用されます。
$set ilnamespace"com.microfocus.book"
$set ilusing"java.lang"
class-id BookException inherits type Exception.
working-storage section.
copy "book-error-codes.cpy".
01 exceptionCode binary-long.
*>> <summary>
*>> Constructor. Pass in the reason for the exception.
*>> </summary>
*>> <param name="eCode">The error code of the exception</param>
method-id new public.
local-storage section.
procedure division using by value eCode as binary-long.
set exceptionCode to eCode
end method.
*>> <summary>
*>> Returns the Exception code.
*>> </summary>
*>> <returns>The Exception code</returns>
method-id get property Code.
procedure division returning lnkCode as binary-long.
set lnkCode to exceptionCode
end method.
*>> <summary>
*>> Return an exception message.
*>> </summary>
*>> <returns>The exception message</returns>
method-id getMessage override.
procedure division returning lnkMessage as string.
evaluate exceptionCode
when DataFileNotFound
set lnkMessage to "Error: Data file not found"
when StockItemNotFound
set lnkMessage to "Error: Stock item not found"
when NoMoreItemsLeft
set lnkMessage to "No more items left"
when ItemAlreadyExists
set lnkMessage to "Error: Item already exists"
when FileError
set lnkMessage to "File error"
end-evaluate
end method.
end class.