• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compile time error or Runtime Exception

 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have one doubt; in java code we can easily distinguish compile time errors and runtime Exceptions. When it comes to servlets to we can identify it we get compile time errors when using javac command and runtime exceptions when we call it . But in case of Jsp's how can we identify this because Jsps are compiled and executed by the container by looking at the syntax you can tell it will give compile time errors; but not always i have seen questions which are very difficult to identify. Can any body give me some clues on it.

Thanks
[ September 22, 2008: Message edited by: raja ram ]
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi raja ram,


commonly IDE will check the syntax error in jsp ... if not we can not sat there is nothing compile time error...
........................................................................
i guess in jsp translation error is called compile time error
........................................................................

correct me, if i am wrong
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Any Updates on this, Can any body throw some light on this.

Thanks
 
Sarat Koduri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya even i am eager to know how to pin point this.. does some body out there to help.. us.. on this..
 
Ranil Liyana Arachchige
Ranch Hand
Posts: 71
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As far as I know ,to distinguish between the compile time errors , translation time errors and runtime errors we could follow a simple rule,

1. to identify translation time errors,

if tags which are in a JSP file can be transformed in to a standard servlet source file there would not be a translation time error.

which means for and example as long as you can translate something written in either a scriptlet , EL , standard tag , or a custom tag to a servlet SOURCE file there would not be a translation time error.

also if you see any . scriptlet , EL syntax , Standard tag syntax , custom tag syntax which doesn't follow the expected syntactical way those would result in a translation time error.

ex: <%! int i = 0 %> translation time error : the translator knows before hand that any scriplet declaration must be terminated with a semicolon, so if you omit the semicolon the jsp translator knows that there is something missing in the declaration, and the translator need not to wait till the compile time , it would say, "ok this is not as it is supposed to be , so i do not want to even compile this!!!". In short the translator can not translate something which is not complete yet.

EL : <input type="text" value=${pageScope.name} /> This would also give you a translation time error. Because EL translator knows that there must be quotes place enclosing the EL expression value="${pageScope.name}" , hence the EL translator would not wait till the EL expression is evaluated, it would say, "mm I need exact EL syntax, there must be quotes around it so this can not be translated!!"

for simple tag , standard tags even if you omit some required attribute or if you add undeclared attributes the translator would not let you pass that to the compiler, it would complain long before that.


Now if you see that the JSP code can fairly well be translated into a Servlet Source file then look for any java syntax errors in that. those would make compile time errors.for example you declare some local variable and you use that variable inside the service method without initializing it, this would not be caught by the translation as there is nothing which prevents it from translating that JSP code int a full servlet source file, the problem becomes visible only when the compiler start checking the source code of the servlet, then the compiler would see , "oh this variable is not initialized and according to my JAVA syntax rules this must be initialized before being used by anyone. so I can not let this compile!" , likewise any JAVA syntax errors would be caught by the compiler at the compile time.

if compile time JAVA code is syntactically correct everything else happens during the runtime,
ex: if there is a custom tag which accept request time attribute value is most likely to throw a runtime exception if it doesn't receive expected type of object etc.


so always when you see a problem,

follow the following pattern , first see if it can be translated without errors , and then compile time errors and then runtime errors

1. Translation Time Error
2. JAVA compile time Error
3. Runtime Error

These are just a simple set of rules that you can use when answering a question, these may not give you exact answer at all the times , but most of the time this strategy works, and it is good to have something than having nothing

Hope this would be helpful to everyone

Regards,
Ranil LiyanaAracchi
 
Sarat Koduri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranil.. thats a very nice explanation.. Rock on...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic