This is maybe a stupid question, but I want to know if my code is programmatically correct.
private void Connect()
{
try
{
// I will do something here
}
catch(Exception ex)
{
// If something bad happened
// I want to ignore the problem and continue the execution
// So, nothing will be placed in the catch block
}
}
Thanks in advance.
I don’t recommend trying to ignore the “catch” in any exception handling. You should make it a habit to deal with exceptions as they crop up, it’s good practice. However, if you need the logic to continue executing, then you can always add the “finally” block, and move on from the exception.
As most have pointed out, ignoring the exception is not recommended. In most cases, even if it doesn’t seem like it can’t affect anything else, it most likely will cause issues down the road.
I would suggest that you log the exception in some way. At the very least you will get an accurate reading of the failure ratio of the code inside of the “try” block. This might help you later on if you decide to refactor the code.