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
tryblock. Obviously you will only ever get there if there wasn’t an exception before: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«.