• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception  RSS feed

 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


compiler error at line 1

please explain me


P.S:i donno why peoples are not replying to my post please do reply.... though it is having silly questions...
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi paramesh

I think scope of object p in the try block is over when block ends
if u move the println statement next to object creation statement it works
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(sorry friends i click the enter button mistakenly
Hi paramesh

I think scope of object p in the try block is over when block ends
if u move the println statement next to object creation statement it works
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

The compilation error is caused by a problem in the variable scope "p".

p is defined inside the try{} and is not accesible after the "catch".

If you want to use this variable outside the catch you must declare it outside the try:


Param p = null;
try{
p = new Param();
} catch {

}

System.out.println(p.a);
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

P.S:i donno why peoples are not replying to my post please do reply.... though it is having silly questions...


Take it in a correct sense

your are asking basic doubt......i hope UR not understood basic concepts correctly otherwise UR not thinking for sometime before asking
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!