M
Madhur Ahuja
Consider this code segment:
class wrap
{
public static void main(String args[])
{
int n;
try
{
n=Integer.parseInt(args[0],10);
}
catch(Exception ArrayIndexOutOfBoundsException)
{
System.out.print("pass the argument");
System.exit(0);
}
System.out.println(n*2);
}
}
Compilation produces this error:
E:\programs\java1\wrap.java:15: variable n might not have been initialized
System.out.println(n*2);
^
I wonder why compiler produces this error, since the statement
n=Integer.parseInt(args[0],10); and produce the valid output since the
exception
is handled.
What should I do to avoid this kind of error.
--
Winners dont do different things, they do things differently.
Madhur Ahuja
India
Homepage : http://madhur.netfirms.com
Email : madhur<underscore>ahuja<at>yahoo<dot>com
class wrap
{
public static void main(String args[])
{
int n;
try
{
n=Integer.parseInt(args[0],10);
}
catch(Exception ArrayIndexOutOfBoundsException)
{
System.out.print("pass the argument");
System.exit(0);
}
System.out.println(n*2);
}
}
Compilation produces this error:
E:\programs\java1\wrap.java:15: variable n might not have been initialized
System.out.println(n*2);
^
I wonder why compiler produces this error, since the statement
n=Integer.parseInt(args[0],10); and produce the valid output since the
exception
is handled.
What should I do to avoid this kind of error.
--
Winners dont do different things, they do things differently.
Madhur Ahuja
India
Homepage : http://madhur.netfirms.com
Email : madhur<underscore>ahuja<at>yahoo<dot>com