What I am trying to do is throw an exception inside the class.
And then be able to catch it outside when executing.
class api {
public function __construct($user_id, $token) {}
public function post($data) {
throw new customException\Post('Error 1');
}
}
try {
$api = new api('id','key');
$output = $api->post($data);
} catch(customException\Post $e) {
var_dump($e);
} catch(exception $e) {
var_dump($e);
}
How would I get something like this to work?
I cannot get customException\Post
to work like that...why is that?
When I use customException
I get this error:
Uncaught ArgumentCountError: Too few arguments to function api::__construct(), 1 passed in /var/www/.../api_2.3.php on line 81 and exactly 2 expected in /var/www/.../api_2.3.php:28
$api = new api('id','key');
? Also are you using an autoloader? – Lawrence Cherone Jul 15 '18 at 0:34