Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an opposite of catch?

By running the following, you can run code if an error is thrown.

try {
    // test
} catch (e) {
    // error output
}

Is there a similar way to run code only if no error is thrown?

like image 933
Himmators Avatar asked Dec 11 '22 16:12

Himmators


1 Answers

Sure there is, see the comment inline.

try {
// test
// No error is thrown if program control reaches here
} catch {
// error output
}

Consider using an additional try block in the "No error is thrown" part if you don't want the outer catch to handle any other errors.

like image 106
Bathsheba Avatar answered Dec 27 '22 18:12

Bathsheba