Exception Handling Flashcards

1
Q

What is Exception handling ?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In PHP, exceptions provide a way to handle ___ gracefully without ___ the application

A

errors
crashing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

4 Key Concepts of Exception Handling in PHP

A

1 Try Block,
2 Catch Block,
3 Throw Statement,
4 Finally Block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The try block contains the code that may potentially throw an ___

A

exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The _____ is responsible for handling the exception thrown by the try block.

A

Catch block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

You can throw an exception using the ____ keyword. This indicates that an error has occurred.

A

throw

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The ___ block, if used, will execute after the try and catch blocks, regardless of whether an exception was thrown or caught.

A

finally

This is useful for cleanup operations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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.”;
}

A

try
throw
catch
finally

How well did you know this?
1
Not at all
2
3
4
5
Perfectly