I'm trying to call a function inside try block and if it fails, catch an exception. My code doesn't work right, what am I doing wrong? Sorry, I'm new on exceptions. Anybody? Any help appreciated :D
What I tried and what doesn't works:
- function check ($func) {
- try {
- call_user_func($func);
- } catch (Exception $e) {
- echo "An error occurred.";
- }
- }
-
- function test () {
- echo 4/0;
- }
-
- check("test");
Returns just "INF" and "Division by zero" error, but should catch that exception and return "An error occurred."