Java error illegal start of type

The Java error illegal start of type occurred in your code when the starting braces of catch block is not used after the close of try block.

Java error illegal start of type


The Java error illegal start of type occurred in your code when the starting braces of catch block  is not used after the close of try block. 

Understand with Example

In this tutorial we want to describe a code that helps you in understanding the coedeof Illegal start  type, for this we have a class name Illegalstartoftype.Inside this main method we have a try block that  include -

1)InputStreamReader-An InputStreamReader is the way to convert from byte stream into character stream.

2)Buffered Reader- This used to read a text from a input stream to provide you efficient mean of reading character.

3)System.out.println-This is used to display the result on the command prompt

we have taken a variable string that is used to store the number entered on your command prompt and read the number from it by calling a readline method( ) . The for loop is  used  to check the condition if the value of  i<j ,the system.out.print display the value of i in the try block. Otherwise the try block is caught by subsequent catch block to handle the error in the try block.


public class Illegalstartoftype {

  public static void main(String args[]) throws Exception {
  InputStreamReader inputStreamReader = new InputStreamReader(;
  BufferedReader br = new BufferedReader(inputStreamReader);

  System.out.println("Enter a number : ");
  String num = br.readLine();

  int j = Integer.valueOf(num);
  for (int i = 0; i < j; i++) {
  }catch(Exception ex){

On Compilation the code show an illegal start of type error.

Compiling source file to /home/girish/NetBeansProjects/errors/build/classes
7'try' without 'catch' o'finally'

18: illegal start of type

  }catch(Exception ex){
BUILD FAILED (total time: seconds)

To solve this error check the closing braces of try after that only start catch

Download code
Share on Google+Share on Google+

Java error illegal start of type

Posted on: November 3, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Java error illegal start of type   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
Rithvik Mandal
July 14, 2013
problem please help illegal start of type.....

import*; class mobile1 { public static void main()throws IOException; BufferedReader br=new BufferedReader(new InputStreamReader(; { System.out.println("CHOICE ANY ONE"); System.out.println("1.CALLING"); System.out.println("2.MESSEGING"); i=Integer.parseInt(br.readLine()); } switch(i) { case 1:BufferedReader br=new BufferedReader(new InputStreamReader(; System.out.println("ENTER 10 DIGITS NUMBER"); int i = Integer.parseInt(br.readLine); system.out.println("calling now....."); system.out.println("IT COST YOU 2 MIN"); break; case 2:BufferedReader br=new BufferedReader(new InputStreamReader(; System.out.println("ENTER text"); int i = Integer.parseInt(br.readLine); system.out.println("sending"); system.out.println("IT COST YOU 1 RUPPEES"); break; } } }