Exception Handling - 12 | 12. Exception Handling | Advanced Programming
K12 Students

Academics

AI-Powered learning for Grades 8–12, aligned with major Indian and international curricula.

Professionals

Professional Courses

Industry-relevant training in Business, Technology, and Design to help professionals and graduates upskill for real-world careers.

Games

Interactive Games

Fun, engaging games to boost memory, math fluency, typing speed, and English skills—perfect for learners of all ages.

Interactive Audio Lesson

Listen to a student-teacher conversation explaining the topic in a relatable way.

Introduction to Exceptions

Unlock Audio Lesson

0:00
Teacher
Teacher

Today, we are delving into the world of exceptions! Let's start with a basic question: what do you think an exception in programming is?

Student 1
Student 1

I think it's an error that happens when a program runs.

Student 2
Student 2

So, it interrupts the program, right?

Teacher
Teacher

Exactly! An exception is an event that disrupts the normal flow of execution in a program. Now, can anyone tell me the different types of errors we might encounter?

Student 3
Student 3

Compile-time errors, runtime errors, and logical errors?

Teacher
Teacher

Great job! Compile-time errors are detected during coding, while runtime errors occur during execution, and logical errors are flaws in the logic itself. Let’s remember this with the acronym 'CRL' for Compile, Runtime, and Logical!

Student 4
Student 4

I like that! It's easy to remember.

Teacher
Teacher

Fantastic! So, moving on, can someone explain the difference between an exception and an error?

Student 1
Student 1

An exception can be handled, but an error is usually serious and can't be.

Teacher
Teacher

Exactly right! Now let's summarize: Exception handling is crucial for maintaining program flow and preventing crashes.

Exception Hierarchy and Keywords

Unlock Audio Lesson

0:00
Teacher
Teacher

Now that we understand what exceptions are, let’s talk about how Java handles them. What do you think about the exception hierarchy in Java?

Student 2
Student 2

It has Throwable at the top, and then it splits into Error and Exception?

Teacher
Teacher

Exactly! The hierarchy starts with `java.lang.Throwable`, which branches into `Error` and `Exception`. Errors are usually fatal, while exceptions are more manageable. Let's remember 'E=MC²' where E equals Errors and MC² stands for Manageable Condition for Exceptions!

Student 3
Student 3

That’s a fun way to remember it! What about the keywords we should know?

Teacher
Teacher

Good question! We have several key terms: `try`, `catch`, `finally`, `throw`, and `throws`. Can anyone explain the purpose of these keywords?

Student 4
Student 4

`Try` defines a block to test for errors, right?

Teacher
Teacher

Correct! And what about `catch`?

Student 1
Student 1

It handles the exception thrown by the `try` block!

Teacher
Teacher

Perfect! Finally, can anyone summarize what we’ve learned about the exception hierarchy and keywords?

Student 2
Student 2

Exception handling helps manage errors, and we have important keywords to implement it effectively!

Checked vs. Unchecked Exceptions

Unlock Audio Lesson

0:00
Teacher
Teacher

Let’s dive deeper into types of exceptions: Checking vs. Unchecked. What do you know about checked exceptions?

Student 3
Student 3

They must be caught or declared, right?

Teacher
Teacher

Exactly! Checked exceptions are verified at compile time. Can anyone give an example?

Student 4
Student 4

How about `IOException`?

Teacher
Teacher

That’s one! Now, what’s the difference with unchecked exceptions?

Student 1
Student 1

Those are checked at runtime, like `NullPointerException`.

Teacher
Teacher

Great! Remember: Checked exceptions must be handled, while unchecked ones are the programmer's responsibility. Let's use 'CU for Checked and U for Unchecked' to recall this.

Student 2
Student 2

That’s easy to remember! Thanks!

Teacher
Teacher

Great work, everyone! In summary, checked exceptions require handling, while unchecked need programmer vigilance.

Best Practices in Exception Handling

Unlock Audio Lesson

0:00
Teacher
Teacher

Now, let’s discuss best practices in exception handling. Who can start us off?

Student 2
Student 2

We should catch specific exceptions instead of generic ones!

Teacher
Teacher

Exactly! It helps pinpoint issues. What else?

Student 3
Student 3

We shouldn’t suppress exceptions silently.

Teacher
Teacher

Correct! It’s crucial to log details and never ignore them. Let’s remember this with 'CLO for Catch, Log, and Openly handle exceptions'.

Student 4
Student 4

I like that! Are there more practices?

Teacher
Teacher

Of course! Always use the `finally` block for resource cleanup and avoid exceptions for normal control flow. Can anyone summarize the key practices?

Student 1
Student 1

Catch specific exceptions, log them, and always clean up resources!

Teacher
Teacher

Perfect! Always remember these practices to write effective and robust code.

Exception Propagation

Unlock Audio Lesson

0:00
Teacher
Teacher

Let’s discuss exception propagation. What happens if an exception isn't caught in a method?

Student 4
Student 4

It propagates to the calling method?

Teacher
Teacher

Exactly! Can anyone explain how that looks in code?

Student 1
Student 1

If `methodA` calls `methodB` which throws an exception, `methodA` should handle it or declare it as throws!

Teacher
Teacher

Spot on! Remember, propagation allows higher-level methods to handle exceptions, which can lead to a cleaner separation of concerns. Use 'P for Propagation' to keep this in mind.

Student 2
Student 2

Thanks for the tips! This is really helpful!

Teacher
Teacher

In summary, understanding exception propagation is key for clean error management in larger systems.

Introduction & Overview

Read a summary of the section's main ideas. Choose from Basic, Medium, or Detailed.

Quick Overview

This section introduces the concept of exception handling in programming, emphasizing its role in dealing with errors gracefully.

Standard

Exception Handling is a vital aspect of programming that allows developers to manage errors and exceptions that occur during the execution of a program. It provides a structured way to detect, handle, and recover from runtime errors, enhancing software reliability and maintainability.

Detailed

Exception Handling Overview

In programming, errors are a common occurrence, ranging from unpredictable inputs to logical issues. Without effective management, these errors could lead to program crashes. Exception Handling presents a systematic approach to addressing runtime errors, ensuring that software remains robust and reliable.

This section specifically emphasizes Java-style exception handling, detailing the types of errors, the exception hierarchy, and essential keywords such as try, catch, finally, throw, and throws. Classic distinctions between checked and unchecked exceptions are discussed, highlighting their unique characteristics and how they can be handled.

Furthermore, we explore intricate exception handling techniques like nested try blocks and multiple catch statements, along with indispensable best practices for managing exceptions effectively. The section aims to leave developers with a comprehensive understanding of how to implement exception handling correctly, enhancing code quality and user experience.

Youtube Videos

Advanced Exception Handling in Python
Advanced Exception Handling in Python
Exception Handling in Python | Python Tutorial - Day #36
Exception Handling in Python | Python Tutorial - Day #36
Master Exceptions in Java: Try, Catch, Finally, Throw, Throws, try-with-resources & Custom Exception
Master Exceptions in Java: Try, Catch, Finally, Throw, Throws, try-with-resources & Custom Exception
Exception Handling Tips in Python ⚠ Write Better Python Code Part 7
Exception Handling Tips in Python ⚠ Write Better Python Code Part 7
Java Exceptions | Exception Handling | try catch block | Throw and Throws Keyword in Java in Hindi
Java Exceptions | Exception Handling | try catch block | Throw and Throws Keyword in Java in Hindi
#63 Python Tutorial for Beginners | Exception Handling
#63 Python Tutorial for Beginners | Exception Handling
47.Structured Exception Handling - Windows System Programming in C/C++
47.Structured Exception Handling - Windows System Programming in C/C++
Exception Handling in Java Tutorial
Exception Handling in Java Tutorial
#11  Exception Handling Explained 🔥 | try-catch, throw, throws, finally | Beginner to Pro
#11 Exception Handling Explained 🔥 | try-catch, throw, throws, finally | Beginner to Pro
My FAVORITE Error Handling Technique
My FAVORITE Error Handling Technique

Audio Book

Dive deep into the subject with an immersive audiobook experience.

Introduction to Exception Handling

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

In the world of programming, errors are inevitable. Programs often deal with unpredictable inputs, system-level interruptions, or logical faults. Without proper handling, such errors can cause the program to crash or behave abnormally. Exception Handling provides a structured mechanism to detect, handle, and recover from runtime errors in a clean and manageable way. Exception handling is crucial for building robust, reliable, and maintainable software. Modern programming languages like Java, C++, Python, and C# offer built-in support for exception handling. In this chapter, we will focus primarily on Java-style exception handling, as it is the standard for many object-oriented and enterprise-level applications.

Detailed Explanation

In programming, it's common to encounter unexpected issues that can interrupt a program’s normal operations, such as invalid user input or lack of system resources. Exception handling is a mechanism designed to manage these errors, allowing programs to continue running or shut down gracefully instead of crashing outright. Various programming languages provide their own ways to handle exceptions; for this chapter, we will specifically focus on how Java handles exceptions since it's widely used in software development.

Examples & Analogies

Imagine you're a chef in a busy kitchen. You prepare meals based on orders, but sometimes you run out of an ingredient or find that a piece of equipment malfunctions. Instead of the kitchen shutting down completely, you can have a plan to substitute ingredients or use backup tools. Similarly, exception handling allows programmers to manage issues that arise during program execution without crashing the entire program.

What is an Exception?

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions.

Detailed Explanation

An exception is essentially a signaling mechanism used within programming languages to indicate that something unexpected has occurred. When a particular event disrupts the normal sequence of operations—like trying to divide by zero—it raises an exception that must be handled by the program to ensure it doesn't crash.

Examples & Analogies

Think of an exception as a car's check engine light. When the engine encounters a problem, the light alerts the driver instead of the engine simply failing without warning. The driver can then take action to resolve the issue rather than continue driving into potential danger.

Types of Errors

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

• Compile-time Errors: Syntax or semantic errors (e.g., missing semicolon, undeclared variables).
• Runtime Errors: Errors that occur during execution (e.g., divide by zero, file not found).
• Logical Errors: Flaws in the algorithm or logic (e.g., incorrect output due to wrong formula).

Detailed Explanation

Errors in programming can be categorized into three main types:
1. Compile-time Errors occur when the code is being compiled - these are typically syntax-related mistakes like misspellings or forgetting punctuation.
2. Runtime Errors happen during the execution of the program, where unforeseen situations arise. An example can be trying to access a file that does not exist.
3. Logical Errors are more subtle, relating to incorrect algorithms that produce wrong results, meaning the code runs without crashing but doesn't behave as intended.

Examples & Analogies

Consider three types of mistakes when making a cake: a compile-time error is like forgetting to add sugar (you face the problem before baking), a runtime error is like realizing halfway through the baking that your oven isn't set correctly (you encounter the problem while it's 'cooking'), and a logical error is like mixing up the amounts of flour and salt, resulting in a cake that doesn't taste good even if it looks fine.

Exception vs. Error

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

• Exception: Recoverable condition (e.g., FileNotFoundException).
• Error: Serious issues (e.g., StackOverflowError, OutOfMemoryError) which are usually not handled in the code.

Detailed Explanation

In programming, we distinguish between exceptions and errors. An exception represents conditions that can be recovered from, and the codes typically include mechanisms to address them, such as retrying an operation. Conversely, an error depicts a more severe issue that usually indicates a problem outside the programmer's control and is not typically meant to be handled through the usual exception-handling flows.

Examples & Analogies

Imagine a teacher (exception) who can give you a second chance on a test if you ask nicely, versus a principal (error) who can expel students for severe violations without room for negotiation. The teacher's approach allows for recovery and improvement, whereas the principal's decisions are usually final.

Need for Exception Handling

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

• Prevents abrupt termination.
• Increases code readability and maintainability.
• Allows centralized error management.
• Separates normal logic from error-handling logic.

Detailed Explanation

Utilizing exception handling provides several advantages in programming: 1) it prevents programs from terminating unexpectedly due to errors. 2) It makes the code more organized and readable by separating error-management from standard logic pathways. 3) It centralizes error handling, allowing developers to manage various exceptions in a systematic manner. Overall, it provides a structured approach that enhances the quality and reliability of software.

Examples & Analogies

Consider a safety net in a circus act. The acrobats perform their routines while knowing the net is there to catch them if they fall. This prepares them for failures without jeopardizing the entire performance, much like how exception handling keeps your program running smoothly even when errors are encountered.

Exception Handling Keywords

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

• try: Used to define a block of code to be tested for errors.
• catch: Handles the exception thrown by the try block.
• finally: A block that is always executed, regardless of exception occurrence.
• throw: Used to explicitly throw an exception.
• throws: Declares exceptions that a method may throw.

Detailed Explanation

Java provides specific keywords for exception handling which include:
1. try establishes a block of code that could potentially trigger an exception.
2. catch captures and handles specific exceptions thrown by the try block.
3. finally ensures execution of code at the end, whether an exception occurred or not, typically for cleanup.
4. throw allows a programmer to manually trigger an exception when specific conditions are met.
5. throws is used in method definitions to indicate that certain methods may propagate exceptions to the caller, alerting them to the possibility of failure.

Examples & Analogies

Think of a restaurant where the kitchen is the 'try' block, attempting to prepare a dish. If a problem arises—like a missing ingredient—the 'catch' block is the server who knows how to handle customer complaints. The 'finally' block is when the kitchen cleans up, the 'throw' is like a chef declaring a food item unfit, and 'throws' is the waitstaff informing the customers of possible menu changes ahead.

Checked vs Unchecked Exceptions

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Checked Exceptions
• Checked at compile time.
• Must be either caught or declared using throws.
• Examples: IOException, SQLException.

Unchecked Exceptions
• Checked at runtime.
• Programmer's responsibility to avoid these.
• Examples: NullPointerException, ArithmeticException.

Detailed Explanation

In Java, exceptions are categorized into checked and unchecked exceptions. Checked exceptions are those that are analyzed at compile-time. You must either handle these exceptions in your code or declare them using the throws keyword. Examples include IOExceptions, often related to file handling. Unchecked exceptions, on the other hand, are not checked during compilation, meaning errors like NullPointer or ArithmeticExceptions can occur during program execution, and it's the programmer's job to prevent them.

Examples & Analogies

You can think of checked exceptions as requiring a license before driving (the compiler checks if you’re licensed and allows driving, or you won't be allowed to drive). Unchecked exceptions are like the chance of running a red light without a traffic light in place; it's up to the driver to follow the rules and avoid accidents, which cannot be predicted during the initial check.

Multiple Catch Blocks

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

try {
// Risky code
} catch (IOException e) {
// Handle IO
} catch (ArithmeticException e) {
// Handle Arithmetic
} catch (Exception e) {
// Handle all other exceptions
}
• Catch from most specific to most general.
• Only one catch block executes per exception.

Detailed Explanation

In Java, you can have multiple catch blocks to manage different exceptions arising from a single try block. It's important to order catch statements from the most specific to the most general. This means if an exception is thrown that matches a specific catch, that block will execute, and the program will not check further blocks, ensuring targeted and efficient error handling.

Examples & Analogies

Think of a customer service representative who deals with various types of complaints. If a customer calls with a billing issue, the representative addresses that specific issue first (specific catch). If the complaint is about a service outage (more general), they then address it. Once a complaint is resolved with one approach, the representative doesn't need to explore others.

Nested try Blocks

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

You can have try blocks inside try blocks for localized exception handling.

try {
try {
// Nested risky code
} catch (Exception e) {
// Inner exception handling
}
} catch (Exception e) {
// Outer exception handling
}

Detailed Explanation

Java allows for nested try blocks, meaning you can place one try block within another. This feature is useful when you want to handle exceptions at different levels: the inner block can manage specific exceptions related to particular code, while the outer block can handle exceptions that haven't been addressed by the inner block. This localized error handling makes your code cleaner and more maintainable.

Examples & Analogies

Consider an intricate factory where workers are responsible for different assembly lines (outer try). Each worker uses tools that could malfunction (inner try). If one worker’s tool breaks, they can manage that issue independently without stopping the whole factory line. However, if a broader issue arises, a supervisor (outer catch) can take over to manage disruptions.

The finally Block

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

• Executes regardless of exception being thrown or not.
• Commonly used for cleanup activities (e.g., closing files, releasing resources).
try {
// code
} catch (Exception e) {
// handler
} finally {
// always executes
}

Detailed Explanation

The finally block in Java is crucial because it guarantees that specific code will run regardless of whether an exception occurred in the try or catch blocks. It is often used for cleanup operations, such as closing file streams or releasing resources that were allocated. This ensures that your program handles resources efficiently and prevents memory leaks.

Examples & Analogies

Imagine finishing a meal at a restaurant. No matter how the service was—you could have loved it or disliked it—you still pay the bill (finally block) before leaving. This ensures that all processes are wrapped up correctly, much like how the finally block wraps up necessary actions no matter what happened in the earlier steps.

The throw Keyword

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Used to manually throw an exception.
throw new ArithmeticException("Division by zero");

Detailed Explanation

The throw keyword in Java is used when you want to explicitly create and trigger an exception. By doing this, a developer can create conditions under which an exception is necessary. This can help to enforce rules or constraints within their code—for example, signaling that a certain operation cannot be performed due to invalid input or states.

Examples & Analogies

Think of a teacher who drops a failing student from a class because they didn't meet the prerequisites. The teacher effectively 'throws' the student out when they realize the student cannot perform at the acceptable level. This action is similar to manually throwing an exception in programming when a particular condition signifies a problem.

The throws Keyword

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Used in method declaration to propagate exceptions.
public void readFile() throws IOException {
// code that may throw IOException
}

Detailed Explanation

The throws keyword in Java is utilized in method signatures to declare that the method may throw an exception. This informs the callers of the method that they need to handle the potential exception that can be thrown. It flags the method as one that could propagate errors, necessitating careful consideration by developers who utilize it.

Examples & Analogies

Imagine a librarian who warns you that a book might be overdue and incur penalties (throws). When you check out a book, you are informed of the possible fine beforehand, allowing you to manage your borrowing wisely, just like how the throws declaration prepares the caller for potential exceptions.

Custom Exceptions

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

You can define your own exception classes by extending the Exception class.

class AgeTooLowException extends Exception {
public AgeTooLowException(String message) {
super(message);
}
}

Usage:
if (age < 18) {
throw new AgeTooLowException("Age must be 18+");
}

Detailed Explanation

In Java, it's possible to create custom exceptions by deriving new classes from the Exception base class. This allows developers to define specific exception conditions tailored to their application logic. For instance, if certain values must meet particular criteria—like an age threshold—a custom exception can be thrown to signal invalid input.

Examples & Analogies

Imagine a club that only allows members over a certain age. If someone underage attempts to enter, they face a unique situation where a bouncer (custom exception) is positioned to enforce this rule. The bouncer’s authority to bar entry perfectly exemplifies the custom exception, ensuring that only eligible individuals can proceed.

Best Practices in Exception Handling

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

• Catch specific exceptions, not generic ones.
• Don’t suppress exceptions silently.
• Use finally for resource cleanup.
• Avoid using exceptions for normal control flow.
• Log exception details (stack trace).
• Create meaningful custom exceptions.

Detailed Explanation

In order to write effective exception handling code, it is critical to adhere to best practices: 1) Always catch specific exceptions to avoid masking errors. 2) Avoid suppressing exceptions as it hinders debugging and issue resolution. 3) Always use finally to clean up resources like file streams. 4) Do not treat exceptions as a primary control flow mechanism; this is considered poor programming practice. 5) Log important details about exceptions to aid in diagnosis. 6) When creating custom exceptions, ensure they convey meaningful information.

Examples & Analogies

Consider a mechanic who is detailed and precise. When a car comes in, they diagnose the problem (specific exception) rather than guessing at generic symptoms. They log the issue and ensure every tool is in its place before proceeding, just like a developer should when handling exceptions.

Exception Propagation

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

If an exception is not caught in the current method, it propagates to the calling method.
void methodA() {
methodB();
}

void methodB() throws IOException {
// throws exception
}

Detailed Explanation

Exception propagation occurs when an exception raised in one method is not handled, causing it to move up the call stack to the method that called it. This continues until the exception is either caught or reaches the main method. When encapsulating code within methods, developers must be careful to manage exceptions properly throughout the call hierarchy.

Examples & Analogies

Think of passing a message through a chain of people in a relay race. If one runner (method) fails to deliver the message (exception), they pass it up to the next runner without resolving it until someone takes charge, just like how exceptions travel up through method calls until addressed.

Common Exceptions in Java

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Exception Name Type Description
ArithmeticException Unchecked Dividing by zero
NullPointerException Unchecked Object reference is null
ArrayIndexOutOfBounds Unchecked Invalid index access in an array
NumberFormatException Unchecked Invalid number conversion
FileNotFoundException Checked File doesn’t exist
IOException Checked General IO failure

Detailed Explanation

Java programmers often encounter several common exceptions that can occur in their applications. Unchecked exceptions such as ArithmeticException (like dividing by zero) and NullPointerException (referencing a null object) simply indicate problems in algorithms or logic and must be avoided. Checked exceptions, such as FileNotFoundException and IOException, require handling, reflecting issues outside immediate control that must be anticipated and managed.

Examples & Analogies

Imagine a student taking various tests (common exceptions). An ArithmeticException is like failing a math test due to lack of preparation, while a FileNotFoundException is akin to a teacher saying a student didn't submit homework (the submission expected but not found). Each failure type has its implications and requires different handling strategies.

Summary of Exception Handling

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Exception handling is an essential concept in advanced programming that allows developers to gracefully manage runtime errors. By using constructs like try, catch, finally, throw, and throws, developers can write robust and fault-tolerant code. Proper use of exception handling improves code readability, maintainability, and user experience. Remember, exceptions should be treated as exceptions, not as a substitute for logic control.

Detailed Explanation

Exception handling plays a crucial role in programming by allowing developers to manage errors effectively. It uses mechanisms like try/catch/finally to ensure that code can recover from runtime issues, improving not only the functionality but also the readability of the code. Skilled developers implement these practices to enhance the overall user experience since well-handled exceptions can prevent frustration and confusion.

Examples & Analogies

Imagine a doctor diagnosing and effectively treating patients without errors in their records. Just like a thorough doctor manages potential health issues with the right treatments, programmers must manage possible errors and exceptions with effective handling to ensure the program functions correctly and users receive the best experience.

Definitions & Key Concepts

Learn essential terms and foundational ideas that form the basis of the topic.

Key Concepts

  • Exception: A disruptor in program flow that causes errors.

  • Error: A serious issue the program typically cannot recover from.

  • Checked Exception: Must be handled during compile time.

  • Unchecked Exception: Programmer’s responsibility to handle.

  • try, catch, finally: Keywords used for exception handling flow.

Examples & Real-Life Applications

See how the concepts apply in real-world scenarios to understand their practical implications.

Examples

  • When attempting to open a file that doesn’t exist, a FileNotFoundException is thrown as a checked exception.

  • If a program attempts to divide by zero, an ArithmeticException occurs, which is an unchecked exception.

Memory Aids

Use mnemonics, acronyms, or visual cues to help remember key information more easily.

🎵 Rhymes Time

  • To catch an exception, don't fear and fret, use try and catch, avoid the regret.

📖 Fascinating Stories

  • Imagine a knight trying to cross a river. If he can’t, he’ll have to catch a boat or find another way, just like using try-catch to cross over errors in coding.

🧠 Other Memory Gems

  • CLO: Catch, Log, Openly handle exceptions.

🎯 Super Acronyms

CRL

  • Compile-time
  • Runtime
  • Logical errors.

Flash Cards

Review key concepts with flashcards.

Glossary of Terms

Review the Definitions for terms.

  • Term: Exception

    Definition:

    An event that disrupts the normal execution flow of a program.

  • Term: Error

    Definition:

    A serious issue often beyond the program's control, usually not handled in code.

  • Term: Checked Exception

    Definition:

    An exception that must be caught or declared at compile time.

  • Term: Unchecked Exception

    Definition:

    An exception that can occur at runtime, typically due to programming errors.

  • Term: try

    Definition:

    A keyword to define a block of code that may throw an exception.

  • Term: catch

    Definition:

    A keyword to handle the exception thrown by try.

  • Term: finally

    Definition:

    A block that executes after try and catch, regardless of whether an exception was thrown.

  • Term: throw

    Definition:

    A keyword used to explicitly throw an exception.

  • Term: throws

    Definition:

    A keyword used in a method declaration to indicate it may throw exceptions.