Should you favour if statements over exceptions?
Say you have a class
Code:
Player
{
private int turbosLeft;
private car myCar;
public void ActivateTurbo()
{
}
}
And there's a car that has a turboable variable
Code:
Car
{
public bool turboAble = false;
}
Should you generate an exception for each seperate occasion? Ex.
Code:
public void ActivateTurbo()
{
try{myCar.activateTurbo}
catch(NotTurboableException) { }
catch(OutOfTurbosException) { }
}
Or should you favour if-statements? Ex.
Code:
public void ActivateTurbo()
{
if(!myCar.turboAble) { }
else if(this.turbosLeft <= =) {}
}
You always should try to avoid try/catch and exception throw's,
So the solution is quick and simple: if/else-statements it will be! =d