How to take screenshot for only failed test cases using selenium web driver ?

package TechLearn.inJava;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

public class FailureTakeAscreenshot {
    public WebDriver driver;
  
    @Test (description="take Screenshots if Test Case fails")
 
      public void Test() throws IOException{  
      
      try{  
          driver.get("http://techlearn.in/user");  
          driver.findElement(By.id("edit-name")).sendKeys("seleniumlearn.com");  
          driver.findElement(By.id("ABCDEF")).sendKeys("techlearn.in");  // I am taking wrong locator. 
         }  
      catch(Exception e){  
          //Takes the screenshot  when test fails  
          File f = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
          FileUtils.copyFile(f, new File("/home/chinna/Desktop/TechLearn"+".png")); 
       

      }  
      
  }
  @BeforeTest
  public void beforeTest() {
      driver = new FirefoxDriver();
  }

  @AfterTest
  public void afterTest() {
  }

}