Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main
- {
- public static void main(String[] args) {
- Scanner fn = new Scanner(System.in);
- System.out.println("Enter a string ");
- String s = fn.nextLine();
- int n = s.length();
- try{
- if(n<7 || n>18){
- throw new StringIndexOutOfBoundsException("Lenth of String is not expected");
- }
- else {
- System.out.println("Your input is fine");
- }
- }
- catch(StringIndexOutOfBoundsException e){
- System.out.println(e);
- }
- finally{
- System.out.println("This is from finally block");
- }
- }
- }
- /*
- Enter a string
- suresh
- java.lang.StringIndexOutOfBoundsException: Lenth of String is not expected
- This is from finally block
- */
Add Comment
Please, Sign In to add comment