When I use Try/Catch, is there a way just like If/Else to run code if there is no error is detected and no Catch?
try
{
//Code to check
}
catch(Exception ex)
{
//Code here if an error
}
//Code that I want to run if it's all OK ??
finally
{
//Code that runs always
}
Add the code at the end of your try
block. Obviously you will only ever get there if there wasn't an exception before:
try {
// code to check
// code that you want to run if it's all ok
} catch {
// error
} finally {
// cleanup
}
You probably should change your catch in a way that you only catch exceptions you expect and not flat-out everything, which may include exceptions thrown in »code that you want to run if it's all ok«.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With