-
Notifications
You must be signed in to change notification settings - Fork 0
/
05-exception.cob
50 lines (46 loc) · 1.73 KB
/
05-exception.cob
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
IDENTIFICATION DIVISION.
PROGRAM-ID. Exceptions.
****************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT test-file ASSIGN TO "does-not-exist.dat"
FILE STATUS IS test-status.
****************************
DATA DIVISION.
FILE SECTION.
FD test-file.
01 home-address.
05 first-name PIC X(20).
05 last-name PIC X(20).
05 zip PIC 99999.
05 street PIC X(30).
05 city PIC X(30).
WORKING-STORAGE SECTION.
01 test-status.
02 test-status-1 PIC X.
02 test-status-2 PIC X.
****************************
PROCEDURE DIVISION.
DECLARATIVES.
test-error SECTION.
USE AFTER ERROR PROCEDURE ON test-file.
DISPLAY "[E] Caught exception."
DISPLAY " Exception code "
test-status-1 "(" test-status-2 ")".
EVALUATE test-status-1
WHEN 0 DISPLAY " regular execution"
WHEN 1 DISPLAY " end of file"
WHEN 2 DISPLAY " invalid key"
WHEN 3 DISPLAY " permanent file error"
WHEN 4 DISPLAY " error in logical I-O order"
WHEN 9 DISPLAY " other error"
WHEN OTHER DISPLAY " unknown error code"
END-EVALUATE.
END DECLARATIVES.
OPEN INPUT test-file.
DISPLAY "[+] File status : " test-status.
DISPLAY "[+] File status class : " test-status-1.
DISPLAY "[+] File status subclass : " test-status-2.
CLOSE test-file.
STOP RUN.