Exception Handling Flashcards
What is Exception handling ?
Exception handling in PHP is a mechanism that allows developers to manage errors and exceptional conditions that may occur during the execution of a program.
In PHP, exceptions provide a way to handle ___ gracefully without ___ the application
errors
crashing
4 Key Concepts of Exception Handling in PHP
1 Try Block,
2 Catch Block,
3 Throw Statement,
4 Finally Block
The try block contains the code that may potentially throw an ___
exception
The _____ is responsible for handling the exception thrown by the try block.
Catch block
You can throw an exception using the ____ keyword. This indicates that an error has occurred.
throw
The ___ block, if used, will execute after the try and catch blocks, regardless of whether an exception was thrown or caught.
finally
This is useful for cleanup operations
Eg:
____ {
// Code that may throw an exception
___ new Exception(“An error occurred!”);
}
_____ (Exception $e) {
// Handle the exception
echo “Caught exception: “ . $e->getMessage();
}
_____ {
// This code will always execute
echo “This will always run.”;
}
try
throw
catch
finally