I have made a part of code where the user can enter some information to a class from the keyboard.
Students newStudent = new Students(System.in);
System.out.println("Enter username");
String username=newStudent.toString();
System.out.println("Enter name");
String name=newStudent.toString();
System.out.println("Enter surname");
String surname=newStudent.toString();
System.out.println("Enter department name");
String department=newStudent.toString();
System.out.println("Enter registration number");
String registrationNumber=newStudent.toString();
System.out.println("Your information is:"+username + name + surname + department + registrationNumber);
newStudent.close();
Now I want using the try-catch to check if the username,name,surname,dept name are strings and registration number is int but I can't seem to understand how try catch works.What should I write?