1

i'm new with the try/Catch option in PHP, so i created this:

try {
    $dropbox->Delete($_POST['truncNaam']);
} catch (Exception $e) {
    echo '<div class="error">Exception: '. $e->getMessage() .'</div>';
}

echo "Success";

When an error occurres now, i will see the error but also i will see " SUCCESS ". I don't want that, i want to see the error when it occurress OR i want to show the SUCCESS if there was no exception.

I just can't figure out how to realize that. Can someone explain it to me?

2
  • echo "Success"; should have been inside "try" Right? Commented Jan 11, 2015 at 15:07
  • 2
    Add a die or exit to your catch. Commented Jan 11, 2015 at 15:10

1 Answer 1

2

This should work for you:

try {

    $dropbox->Delete($_POST['truncNaam']);

} catch (Exception $e) {
    echo '<div class="error">Exception: '. $e->getMessage() .'</div>';
    die();

}

echo "Success";

Or you could do something like this:

$caught = false;

try {

    $dropbox->Delete($_POST['truncNaam']);

} catch (Exception $e) {
    echo '<div class="error">Exception: '. $e->getMessage() .'</div>';
    $caught = true;

}

if (!$caught) {
    echo "Success";
}
Sign up to request clarification or add additional context in comments.

1 Comment

I thought there might be an option in the try/catch, but i assume there is not. Then i take the second option, don't like to use die(). Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.