100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Error Handling in COBOL

Learn how COBOL programs detect and respond to runtime errors using FILE STATUS codes, the ON SIZE ERROR and ON OVERFLOW phrases, and structured exception handling with USE and declaratives.

Structured ProgrammingIntermediate10 min readJul 10, 2026
Analogies

Why Explicit Error Handling Matters in COBOL

Unlike languages with built-in try/catch exception frameworks, classic COBOL requires the programmer to explicitly check for error conditions after nearly every I/O or arithmetic statement, because without that checking the runtime either silently continues with corrupted results or abends the entire job step. A batch program that reads a file without checking FILE STATUS after each READ, for instance, will not automatically detect end-of-file or a record-not-found condition unless the programmer has coded an AT END or INVALID KEY clause, or wired up a FILE STATUS check, to catch it. This explicit, statement-by-statement discipline is a defining characteristic of COBOL error handling, and mainframe shops that skip it routinely suffer abends deep into multi-hour batch runs that then require an operator to diagnose from a dump.

🏏

Cricket analogy: Skipping error checks in COBOL is like a fielder not checking whether they've actually gathered the ball cleanly before throwing to the stumps; without that explicit check, a misfield can go unnoticed until the run-out attempt fails at the worst moment.

FILE STATUS Codes and I/O Error Checking

Declaring a two-character FILE STATUS field in the SELECT clause, such as SELECT CUSTFILE ASSIGN TO CUSTDD FILE STATUS IS WS-CUST-STATUS, causes the runtime to populate that field after every OPEN, READ, WRITE, REWRITE, DELETE, and CLOSE against the file, letting the program branch on the two-digit code immediately afterward. A status of '00' means the operation succeeded, '10' signals end-of-file on a sequential READ, '23' means record-not-found on an indexed READ by key, and '35' means the OPEN failed because the file does not exist, and disciplined programs check WS-CUST-STATUS after every single I/O verb rather than assuming success. Many shops standardize this pattern by writing a single shared paragraph, such as 9000-CHECK-FILE-STATUS, invoked via PERFORM after each I/O operation, so that unexpected status codes are logged and the program terminates cleanly with a meaningful message instead of an unexplained abend.

🏏

Cricket analogy: A FILE STATUS code is like the third umpire's decision review readout, DECISION: OUT or DECISION: NOT OUT, giving the on-field umpire an explicit two-part signal to act on rather than guessing what happened on a close run-out.

ON SIZE ERROR, ON OVERFLOW, and Declaratives

Arithmetic statements such as COMPUTE, ADD, SUBTRACT, MULTIPLY, and DIVIDE support an optional ON SIZE ERROR imperative-statement clause that executes only when the result would overflow the receiving field's PICTURE clause or when a division by zero is attempted, letting the program substitute a default, log a warning, or branch to cleanup logic instead of silently truncating a financial total. STRING and UNSTRING statements have an analogous ON OVERFLOW clause that fires when the receiving field is too small to hold the concatenated or split result. For broader, file-level exception handling across many paragraphs, COBOL's DECLARATIVES section, placed at the start of the PROCEDURE DIVISION and paired with USE AFTER STANDARD ERROR PROCEDURE ON file-name, lets a program centralize I/O error handling for a specific file so every READ or WRITE against it automatically triggers the declarative paragraph on any non-successful FILE STATUS, without a manual check after every single statement.

🏏

Cricket analogy: ON SIZE ERROR is like a stadium's electronic scoreboard having a built-in rule for when a team's total would exceed the display's digit limit, triggering a special overflow indicator rather than showing a wrapped, meaningless number.

cobol
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  WS-CUST-STATUS      PIC XX.
       01  WS-TOTAL-AMOUNT     PIC 9(5)V99.
       01  WS-INCREMENT        PIC 9(5)V99 VALUE 99999.99.

       PROCEDURE DIVISION.
           READ CUSTFILE
               INVALID KEY
                   DISPLAY 'CUSTOMER NOT FOUND: ' WS-CUST-STATUS
           END-READ

           IF WS-CUST-STATUS NOT = '00' AND WS-CUST-STATUS NOT = '23'
               PERFORM 9000-FILE-ERROR-ABORT
           END-IF

           ADD WS-INCREMENT TO WS-TOTAL-AMOUNT
               ON SIZE ERROR
                   DISPLAY 'TOTAL WOULD OVERFLOW, CAPPING VALUE'
                   MOVE 99999.99 TO WS-TOTAL-AMOUNT
           END-ADD.

The most common FILE STATUS codes to memorize: '00' success, '10' end-of-file, '22' duplicate key on WRITE/REWRITE, '23' record not found, '35' file not found on OPEN, and '9x' codes indicate implementation-specific or environment errors that usually require checking the vendor's runtime documentation.

Relying only on the compiler's default action for an unhandled AT END or INVALID KEY condition is dangerous: if no explicit clause is coded, some COBOL environments simply continue to the next statement with the record area unchanged, silently reprocessing the last successfully read record and corrupting downstream totals, rather than stopping the program.

  • COBOL requires explicit, statement-by-statement error checking rather than providing automatic exception propagation like try/catch.
  • FILE STATUS is a two-character field populated after every I/O verb, with '00' meaning success and other codes indicating specific conditions.
  • AT END and INVALID KEY clauses handle end-of-file and key-not-found conditions directly on READ statements.
  • ON SIZE ERROR catches arithmetic overflow or division by zero on COMPUTE, ADD, SUBTRACT, MULTIPLY, and DIVIDE.
  • ON OVERFLOW catches insufficient receiving-field space on STRING and UNSTRING statements.
  • DECLARATIVES with USE AFTER STANDARD ERROR PROCEDURE centralizes I/O error handling across all operations on a given file.
  • Failing to code explicit error clauses can let a program silently continue with corrupted or stale data instead of failing safely.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#COBOLStudyNotes#ErrorHandlingInCOBOL#Error#Handling#COBOL#Explicit#ErrorHandling#StudyNotes#SkillVeris

Frequently Asked Questions

21 categories · pick one to explore

Where can I get free study notes for programming and tech subjects?
SkillVeris offers completely free study notes covering programming and tech subjects, with no signup fees or paywalls. The notes are structured by course and topic, written for quick understanding, and enriched with the Learn Through Hobbies analogy method, so you can revise concepts through cricket, music, gaming, cooking and more.
Are SkillVeris study notes good for exam revision?
Yes, the study notes are designed for efficient revision: each topic answers its heading immediately, keeps explanations concise, and links to related glossary terms and cheat sheets. Students preparing for university exams or certification tests use them as quick revision notes because they distil concepts without the padding of full textbooks.
What subjects do the free study notes cover?
The study notes span the platform's main domains, including AI and machine learning, Python and programming, web development, DevOps, cloud, security and databases. Coverage mirrors the 37 live courses, so notes exist for the topics you are actually studying, and new note sets are added as courses launch.
How are SkillVeris study notes different from regular textbooks?
The notes are answer-first, concise and free, whereas textbooks are long and often expensive. Each section explains one concept directly, then reinforces it through selectable hobby analogies like cricket or cooking. Notes also cross-link to the glossary, blog and cheat sheets, letting you jump to related material instantly instead of flipping pages.
Can I use the developer study material without creating an account?
The study notes are free to access, and SkillVeris does not charge anything for its developer study material at any point. Browsing notes is straightforward from the Study Notes section, and if you want progress tracking, certificates and AI Mentor conversations tied to your learning, a free account unlocks those extras.
Do the study notes explain concepts with analogies?
Yes, this is a signature SkillVeris feature. Study notes use the Learn Through Hobbies method, explaining technical concepts through analogies from twelve domains including cricket, music, gaming, photography, travel, movies, fitness, chess, cooking, finance, business and sports. You can switch the analogy domain instantly to whichever hobby makes the concept click.
Are the revision notes suitable for last-minute exam preparation?
Yes, revision notes on SkillVeris work well for last-minute preparation because every section states the answer in its first sentences, so skimming is genuinely effective. Pair them with the relevant cheat sheet for formulas and syntax, and use the glossary for any unfamiliar term you meet while cramming.
Is there free study material for AI and machine learning?
Yes, SkillVeris provides free study notes across its AI and ML catalogue, covering Python for AI, deep learning frameworks like PyTorch and TensorFlow, Hugging Face Transformers, Large Language Models, RAG, AI agents and MLOps. All of it is free, making it a strong resource for Indian students and global learners alike.
Can beginners understand the study notes, or are they for experts?
Beginners can absolutely use them. The notes are written in plain language, define terms as they appear, and lean on hobby analogies to make abstract ideas concrete. Difficulty scales with the underlying course level, so beginner-course notes stay gentle while advanced-course notes go deeper, and the glossary supports you throughout.
How do study notes connect with SkillVeris courses?
Study notes are organised by course and topic, so they map directly to the structured courses and their 24–40-lesson curriculum. Many learners study a lesson first, then use the matching notes for revision before module assessments and the final exam, where 80 percent is required to pass and earn the certificate.
Are there study notes for Python specifically?
Yes, Python is well covered through notes tied to the Python-focused courses, including Python for AI and ML. Topics span fundamentals through applied machine learning usage. You can reinforce the notes with Python practice in Code Lab, which runs code in your browser with no installation required.
Do the study notes include code examples?
Yes, study notes include code examples wherever a concept is best shown in code, alongside explanations, key points and analogies. Reading a snippet in the notes and then reproducing it yourself in Code Lab is an effective loop, since Code Lab lets you run code in the browser across six languages.
How often is new study material added to SkillVeris?
Study material grows alongside the course catalogue. Whenever new courses join the platform's 37 live courses, matching study notes, glossary entries and cheat sheets are added so the resources stay in sync. Existing notes are also refined over time, so it is worth revisiting topics you studied earlier.
Can I use SkillVeris notes to prepare for technical interviews?
Yes, the notes make excellent interview revision because they compress each concept into direct, answer-first explanations, which mirrors how you should answer interview questions. Combine them with the SkillVeris interview questions feature, which includes readiness scoring, to test whether your revision has actually made you interview-ready.
Are the study notes mobile-friendly for studying on the go?
Yes, the study notes are built to load fast and read comfortably on mobile devices, so you can revise during a commute or between classes. Sections are short and answer-first, which suits small screens, and analogy switching works on mobile too, letting you study anywhere without carrying books.
What is the difference between study notes and cheat sheets?
Study notes explain concepts in depth with context, examples and analogies, making them ideal for learning and revision. Cheat sheets are compact quick-reference summaries of syntax, commands and key facts, ideal once you already understand a topic. Most learners study the notes first, then keep the cheat sheet handy while coding.
Do study notes help if I am stuck on a course lesson?
Yes, reading the matching study notes often clarifies a lesson because the same concept is explained from a different angle, frequently with a different analogy. If you are still stuck, ask the AI Mentor, which answers 24/7 at Quick, Detailed or Deep-dive depth until the idea genuinely makes sense.
Is there free study material for DevOps and cloud topics?
Yes, SkillVeris carries free study notes for DevOps and cloud topics as part of its coverage across 37 live courses. The material suits learners following the DevOps Engineer or Cloud Engineer paths, and it links to related glossary terms and cheat sheets so you can revise the whole toolchain in one place.
Can school or college students in India use these notes for projects?
Yes, students across India and worldwide use SkillVeris notes for coursework, projects and exam preparation, and everything is free, which matters for student budgets. The notes explain concepts clearly enough to cite in project reports, and Code Lab lets you prototype the project code directly in your browser.
How should I combine study notes with other SkillVeris resources?
A proven loop: learn from a course lesson, revise with the matching study notes, look up unfamiliar terms in the glossary, keep the cheat sheet open while practising in Code Lab, and quiz yourself with interview questions. The AI Mentor fills any remaining gaps 24/7, at whatever depth you need.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse