Online · Davao City · Philippines

2D Digital Animation and Story Design Course in Davao City

A 2D digital animation and story design course in Davao City covers Canva layout skills and frame-by-frame animation in OpenToonz—building sequential logic that also supports STEM design thinking.

Animation Davao

1. Introduction: Why File Operations Cause Runtime Errors

In Python file handling, the files your code interacts with do not reside inside the Python script itself; they are stored separately on the hard disk. Because file operations depend on external storage, several common issues can arise:

  • The file you are attempting to open does not exist.
  • The file exists but is located in a different path or directory.
  • The file is not being opened in the correct file mode.

When any of these issues occur during execution, Python raises an error and crashes your program immediately, halting further execution.

2. What Is an Exception?

An exception is a runtime error that occurs while your code is actively running.

  • Without exception handling: Python stops execution, displays a long error message, and terminates the program abruptly.
  • With exception handling: You intercept the error and tell Python what action to take, allowing the application to recover smoothly and continue running without crashing.

3. The try and except Blocks

To prevent crashes, Python provides the try and except keywords:

  • The try block: Encloses code that is suspected of potentially throwing an exception. (Analogy: Just like taking a "try ball" when playing cricket to test the pitch, you tell Python to "try" running this block of code first).
  • The except block: Specifies the exact error type to catch and instructs Python on what corrective action to perform if that error occurs.

4. Example 1: Catching FileNotFoundError Gracefully

The Unhandled Crash

Attempting to open a non-existent file (missing.txt) in read mode causes Python to halt:

# Attempting to read a non-existent file without handling
with open("missing.txt", "r") as file:
    content = file.read()
    print(content)

Because missing.txt does not exist on the hard disk at that path, Python raises a FileNotFoundError and terminates the program.

Handling the Error with try...except

By wrapping the operation inside a try block and catching FileNotFoundError, the program handles the situation cleanly:

# 1. Try attempting the file operation
try:
    with open("missing.txt", "r") as file:
        content = file.read()
        print(content)

# 2. Intercepting FileNotFoundError if the file is missing
except FileNotFoundError:
    print("File not found")

Execution Walkthrough

  • Python attempts to open missing.txt in read mode inside the try block.
  • When it discovers that the file does not exist at that path, it routes execution straight to the except FileNotFoundError: block.
  • Instead of displaying a lengthy crash traceback, it displays a clean, readable message: "File not found".
  • Program execution continues normally with any subsequent lines of code.

5. Example 2: Automatic Recovery (Creating the Missing File)

Exception handling is not limited to displaying error messages; you can also take corrective recovery actions, such as automatically creating a missing file and writing required data into it.

# Target file that does not yet exist on disk
filename = "my_info.txt"

# 1. Attempting to open and read the file
try:
    with open(filename, "r") as file:
        content = file.read()
        print(content)

# 2. If the file is missing, automatically create it and write data
except FileNotFoundError:
    print(f"'{filename}' not found. Creating file and writing data...")

    # Open in write mode ('w') to create the file and store records
    with open(filename, "w") as f_out:
        f_out.write("Name: GitHub Copilot\nAge: 1\n")

    # Read and print the newly written contents
    with open(filename, "r") as f_in:
        content = f_in.read()
        print("File created successfully! Contents:")
        print(content)

Execution Walkthrough

  1. Python attempts to open my_info.txt in read mode.
  2. Because the file does not exist, a FileNotFoundError is triggered.
  3. The except block catches the error and opens my_info.txt in write mode ('w'), which creates the file on disk.
  4. It writes default data into the file (Name: GitHub Copilot, Age: 1).
  5. It then reopens the newly created file in read mode and displays its contents.
  6. This pattern handles runtime failures gracefully and produces clean, predictable application behavior.

Lesson Q&A

Unlike hardcoded variables, files reside externally on the hard disk. File handling operations often encounter real-world storage issues—such as the target file not existing, being located in a different directory path, or being opened in an incorrect mode. If these external issues are unhandled, Python raises a runtime exception and immediately crashes the program.

The try block wraps code that might potentially raise an error or exception during execution. The except block specifies the error type to listen for (such as FileNotFoundError) and defines the specific recovery action Python should take if that error occurs. Using try...except prevents the program from terminating with a crash traceback, allowing it to recover cleanly and continue executing.

Beyond printing a user-friendly error message, an except block can perform automatic recovery actions—such as creating the missing file on the spot. When catching FileNotFoundError, the program can open the filename in write mode ('w'), write necessary initial records or configuration data into it, and then proceed with reading or processing that data smoothly.

What children can learn

WhatsApp +92 322 421 7059

AI and Robotics Club | The 100 Mission AI & Robotics Hero Journey

Recommended self-paced course for parents & educators

OpenToonz for Kids on Udemy.

Disclosure: This page contains affiliate links. We may earn from qualifying purchases at no extra cost to you. Links are intended for parents and educators, not as marketing directed at young children.

Frames and Layouts: Creative Logic for Davao Young Designers

Davao families seeking creative tech can use animation as sequential logic training. Enquire +92 322 4217059. No invented Davao studio.

Frequently asked questions

What design tools are taught in the Davao City 2D digital animation course?

Students learn graphic layout, visual asset creation, and character design in Canva for Kids, combined with frame-by-frame 2D animation and storyboard techniques in OpenToonz.

How does learning digital animation support STEM and robotics logic?

Animation teaches coordinate movement, timeline management, user interface (UI) design, and visual sequencing—critical computational skills needed when building robot interfaces and software games.

How do families in Davao City register for a free demo lesson?

Contact our instructors via WhatsApp directly from this page, view sample student animation reels, and reserve a free live trial class.

Explore related learning

MakatiScratch · Makati ParanaqueSTEAM · Parañaque AlabangAI · Alabang