3 You are developing code and you want to ensure that you in
3) You are developing code and you want to ensure that you include proper error handling. Create a try/catch block that includes assigning a variable tester to the value of 1 inside the try code block. If an error occurs, then the value of tester should be 2. In either case, include a section of code that will always assign the variable validate to a value of “here”. You should ensure that all code is included within the code construct of the try/catch block.
Solution
JAVA CODE
NOTE - Appropriate comments are included.
package trycatchex;
import java.util.Scanner;
public class TryCatchExample {
 public static void main(String args[])
 {
    //declaring the variables.
    int Tester;
    int here;
    int validate=0;
   
    //This is try block which if executes successfully then
    //will the value 1 to Tester variable
    //and variable here will have the value of validate
    try
    {
        Tester=1;
        here=validate;
    }
   
    //This block gets executed if any exception is occurred in above
    //codes and it will assign the value of Tester = 2
    //and variable here will have the value of validate
    catch(Exception e)
    {
        Tester = 2;
        here = validate;
    }
   
    //Note in both cases of try-catch block variable here will have the
    //the value of validate, if any of the blocks run.
 }
}

