Visual Algorithms Meet Motion: mBlock Practice for Mandaluyong Learners
Mandaluyong families gain from visual robotics that stays optional on hardware. Enquire WhatsApp +92 322 4217059. No invented Mandaluyong studio.
mBlock coding and interactive robotics for Mandaluyong lets students write visual algorithms that control motor drives, line-following ideas and light indicators—on screen first, optional hardware later.

In earlier exception handling modules, the primary focus was on intercepting and handling errors generated automatically by Python at runtime. However, robust software design also requires the ability to intentionally generate errors ourselves.
raise keyword.To manually trigger an exception, Python provides the raise keyword.
When using raise, you specify two key components:
ValueError, which signals an objection to the specific value of the data).raise ExceptionType("Descriptive error message")
Using this syntax alerts developers and surrounding code that an input check has failed and indicates where input validation or exception handling is needed.
Consider an application that accepts a person's age. If a user enters a negative value (such as -3), the code uses an if statement to verify that the value is non-negative:
# 1. Simulating an invalid user input
age = -3
# 2. Inspecting the value using an if statement
if age < 0:
# 3. Explicitly raising a ValueError with a custom explanation
raise ValueError("age cannot be negative")
When Python executes this cell in Jupyter Notebook, the condition age < 0 evaluates to True, triggering the raise statement:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In, line 6
3 age = -3
4
5 if age < 0:
----> 6 raise ValueError("age cannot be negative")
ValueError: age cannot be negative
ValueError, matching the exception type explicitly defined in the code.Raising an exception halts execution unless it is caught. In production applications, you can catch the custom-raised exception within a try...except block to log the error or prompt the user for valid data without terminating the program:
try:
user_age = -3
if user_age < 0:
raise ValueError("age cannot be negative")
print(f"User age recorded: {user_age}")
except ValueError as error:
print(f"Validation Error caught: {error}")
Output:
Validation Error caught: age cannot be negative
raise keyword triggers the ValueError when an invalid age is detected.except ValueError as error: block intercepts the error, extracts the custom text message, and prints a controlled notification instead of crashing the program.While Python automatically raises errors for technical failures (such as dividing by zero), it cannot anticipate custom business logic or domain rules on its own. If an application inspects data and finds an invalid or illogical value—such as a negative number entered for a user's age—the programmer can intentionally trigger an error using the raise keyword. This prevents corrupt or illogical data from propagating downstream and signals that an input check or exception handler is required.
The syntax for raising an exception is: raise ExceptionType("Custom explanatory message"). Using the raise keyword, the developer specifies the exception type (such as ValueError when objecting to a data value) along with a descriptive text message explaining the issue (such as "age cannot be negative"). When executed, Python generates that specific error and prints the custom message directly in the traceback.
Because -3 is less than 0, the if condition evaluates to True, triggering the raise statement. Python halts standard execution and outputs a ValueError displaying the exact message: "age cannot be negative". This indicates that an invalid value was detected and must either be corrected by the user or intercepted by an exception handler.
mBlock Coding Fast Track for Beginners 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.
Mandaluyong families gain from visual robotics that stays optional on hardware. Enquire WhatsApp +92 322 4217059. No invented Mandaluyong studio.
mBlock bridges Scratch block coding with physical mBot hardware and AI blocks. Students in Mandaluyong write visual code that executes real-time motor drives, line-following sensors, and LED indicators.
Yes! We utilize interactive software robotics simulators during live online classes, enabling students to write algorithms and simulate robot behavior on screen before purchasing physical hardware.
Click the WhatsApp button on this page to message our admissions team and arrange a free live trial session this week.