I've got an Input helper class that throws an exception if the source array index is undefined.
So if I had something like:
$input = new Input($_GET, $_POST);
$input->get("var1");
$input->get("var2");
$input->get("var3");
$input->get("var4");
It would now be:
$input = new Input($_GET, $_POST);
try {
$input->get("var1");
} catch(Exception $e) {
//handle it
}
try {
$input->get("var2");
} catch(Exception $e) {
//handle it
}
try {
$input->get("var3");
} catch(Exception $e) {
//handle it
}
try {
$input->get("var4");
} catch(Exception $e) {
//handle it
}
I have no idea how I could use less try catch blocks without having to stop execution of the further code if I was to put everything in 1 try catch block.
Is this the correct way of using the try catch function?