📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
🎓 Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
1. What is Exception Handling in PHP?
Answer:
Explanation:
Exception handling in PHP is a way to handle errors and exceptions gracefully during the execution of a program.
2. Which keyword is used to throw an exception in PHP?
Answer:
Explanation:
The 'throw' keyword is used to throw an exception in PHP.
3. What is the purpose of the try block in PHP?
Answer:
Explanation:
A try block is used to wrap the code that may potentially cause an exception.
4. What does the catch block do in PHP?
Answer:
Explanation:
The catch block is used to handle exceptions that are thrown within the associated try block.
5. How do you create a custom exception in PHP?
Answer:
Explanation:
Custom exceptions are created in PHP by extending the built-in Exception class.
6. Can multiple catch blocks be used with a single try block?
Answer:
Explanation:
Multiple catch blocks can be used with a single try block to handle different types of exceptions.
7. What is the purpose of the finally block in PHP?
Answer:
Explanation:
The finally block is used to execute code after try and catch blocks, regardless of whether an exception was thrown or not.
8. Which class do all exceptions extend in PHP?
Answer:
Explanation:
All exceptions in PHP extend the base Exception class.
9. What happens if an exception is not caught in PHP?
Answer:
Explanation:
If an exception is not caught, the script will terminate with a fatal error.
10. What is the correct way to specify the type of exception to catch in PHP?
Answer:
Explanation:
The catch block specifies the type of exception to catch using catch(ExceptionType $e) syntax.
11. How can you rethrow an exception in PHP?
Answer:
Explanation:
An exception can be rethrown in PHP by using the throw keyword again within a catch block.
12. What is the primary purpose of exception handling in PHP?
Answer:
Explanation:
The primary purpose of exception handling is to handle runtime errors in a way that does not crash the program and allows for graceful recovery or termination.
13. Which of the following is a built-in exception in PHP?
Answer:
Explanation:
InvalidArgumentException is an example of a built-in exception in PHP.
14. Can you nest try-catch blocks in PHP?
Answer:
Explanation:
Try-catch blocks can be nested within each other in PHP.
15. What is the output of getMessage() function in an exception object in PHP?
Answer:
Explanation:
The getMessage() function returns the message of the exception that was thrown.
Comments
Post a Comment
Leave Comment