Online · Quezon City · Metro Manila

Arduino Robotics and Electronic Sensors Course in Quezon City

An Arduino robotics and electronic sensors course for Quezon City guides students through breadboard wiring, ultrasonic sensing, servo drivers and introductory control code—simulators first, optional kits under supervision.

Arduino QC

1. Introduction: From Concept to Practice in Exception Handling

In programming, unexpected user inputs or runtime conditions can easily cause an application to fail. Without error handling, Python halts execution and outputs system tracebacks that can disrupt the user experience.

To make programs resilient, Python provides a four-part exception-handling architecture:

  1. try: Wraps the suspect code block you want Python to attempt running.
  2. except: Catches and intercepts specific runtime errors, executing recovery steps rather than crashing.
  3. else: Runs code only if no exceptions occurred inside the try block.
  4. finally: A cleanup block that always executes, regardless of whether an exception occurred or not.

2. Examining Common Runtime Failures

Consider a simple script that asks a user for a number, converts that input into an integer, and calculates the division 10 / number:

# Suspect code vulnerable to user input errors
user_input = input("Enter a number: ")
number = int(user_input)
result = 10 / number
print("Result:", result)

Testing this code across different user inputs demonstrates how unhandled errors arise:

  • Valid input (e.g., 7): 10 / 7 computes successfully and prints the answer cleanly.
  • Zero input (0): Because division by zero is mathematically undefined, Python raises a ZeroDivisionError and terminates execution.
  • Invalid characters (e.g., 'k'): Passing a letter instead of a digit causes int() to fail, raising a ValueError because non-numeric characters cannot be parsed into integers.

3. Intercepting Errors with try and Targeted except Blocks

To prevent crashes, place suspect operations inside a try block and attach targeted except blocks for each anticipated error type. You can also include a generalized fallback block using except Exception as e: to catch unforeseen errors as an object e without breaking the program:

try:
    # Attempting the input conversion and division
    user_input = input("Enter a number: ")
    number = int(user_input)
    result = 10 / number
    print("Result:", result)

# 1. Handling division by zero
except ZeroDivisionError:
    print("You cannot divide a number by zero.")

# 2. Handling non-numeric inputs
except ValueError:
    print("That is not a number.")

# 3. Catch-all for any other unanticipated exceptions
except Exception as e:
    print("An unexpected error occurred:", e)

How Python Evaluates This

  • If the user enters 0, Python bypasses the standard traceback and prints: "You cannot divide a number by zero.".
  • If the user enters a letter like k, Python intercepts the conversion failure and displays: "That is not a number.".
  • Any unexpected runtime problem is captured by except Exception as e:, printing a controlled error message rather than crashing.

4. Adding the else and finally Blocks

To build complete control flow into your error handling, Python allows pairing try and except with else and finally:

try:
    print("Running code...")
    # Clean calculation that does not raise any exception
    number = 5
    result = 10 / number
    print("Calculation successful:", result)

except Exception:
    print("An error occurred.")

else:
    # Executes ONLY if the try block completed with zero errors
    print("No errors found.")

finally:
    # ALWAYS executes in all scenarios
    print("Done.")

Execution Walkthrough

  1. try execution: "Running code..." prints, and 10 / 5 evaluates cleanly to 2.0.
  2. except skipped: Because no exception was raised, all except handlers are bypassed.
  3. else triggered: Because the try block ran without error, Python executes the else block, printing "No errors found.".
  4. finally runs: Regardless of what happened above, Python executes the finally block, outputting "Done.".

Console Output:

Running code...
Calculation successful: 2.0
No errors found.
Done.

5. Summary: Roles of All Four Keywords

Keyword Execution Condition Typical Purpose
try Always executed first Encloses suspect code that could potentially fail at runtime.
except Runs only if an error occurs inside try Catches specific exception types and performs graceful recovery.
else Executes only if NO error occurs inside try Runs follow-up operations that depend on the try block succeeding.
finally Always executes in every case Performs mandatory cleanup actions (e.g., closing files, releasing resources).

Lesson Q&A

try contains the suspect code block that you want Python to attempt running. except executes only if an exception is raised inside the try block, catching the error and displaying a controlled recovery message rather than crashing. else executes only when the try block runs successfully with zero errors. finally executes unconditionally in all scenarios, regardless of whether an exception occurred, was handled, or the code ran cleanly.

If a user inputs 0, dividing any number by zero is mathematically undefined, causing Python to raise a ZeroDivisionError. If a user inputs a non-numeric letter (such as 'k'), the int() function cannot convert the string into an integer, raising a ValueError. Wrapping these operations in targeted except ZeroDivisionError: and except ValueError: blocks intercepts each specific failure and displays a friendly notice (e.g., "You cannot divide a number by zero" or "That is not a number") without halting the program.

The finally block always executes in every situation—whether the try block succeeded, an exception occurred and was caught, or an unanticipated error arose. It is used for mandatory concluding operations and resource cleanup, ensuring that tasks such as releasing system locks, closing open database connections, or finalizing file states run reliably before the program moves forward.

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

mBlock Coding 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.

Breadboard to Behaviour: Arduino Practice for Quezon City Learners

Quezon City families exploring hardware need safe, clear pathways. Simulators first; kits optional. Enquire +92 322 4217059. No invented QC lab.

Frequently asked questions

What real-world hardware skills will students in Quezon City learn in this course?

Students master breadboard circuit wiring, microcontroller programming, ultrasonic distance sensors, servo motor drivers, and basic C++ syntax. Consequently, Quezon City learners gain practical hardware engineering experience suitable for school science fairs and STEM competitions.

Do students in Quezon City need prior electronics experience to join?

No prior experience is required! Our step-by-step curriculum starts from the basics of electric current and logic switches before advancing into complete sensor-guided robot builds.

What is the fastest way to register a Quezon City student for an upcoming Arduino class?

Simply send a quick message to our mentor team via WhatsApp with your child’s age and current experience level to claim a free 1-on-1 trial session.

Explore related learning

BGCRobotics · BGC MandaluyongmBlock · Mandaluyong CebuSTEM · Cebu