• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TryCatchFinally interface.....did you know!!!

 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you are writing a custom tag, you can implement TryCatchFinally interface.
When you choose to do this, if the doStartTag() method throws an exception, the doEndTag() method is NOT called. The flow goes to doCatch( ) method, maybe expected right!.
However, if you choose to return "SKIP_PAGE" in the doEndTag( ), you should realize that the page is NOT skipped in the above scenario (since we never went into the doEndTag() ) and that the evaluation of the page continues.
I din't realize this till I played with a real example. Just thought I would pass this along, then again its me.
Learned something new today!!!
regds.
- satya
 
faiza haris
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx for sharing...
I also came across something similar just now!!!...
In CS&JSP book, it says that print should be inside try/catch block and to report other types of errors t
o client, u can declare doStartTag() to throw JspException
I dont know about doCatch(). Please state your example if u can? thanx for any help!
faiza
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In CS&JSP book....
I thought CS&JSP follows the previous specs version. jsp 1.1 and servlets 2.2.
You need MS&JSP which follows jsp 1.2 and servlets 2.3 specs.....
- satya
 
Rohit Poddar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Satya,
I looked at the TryCatchFinally Interface in API spec. and following is the prototypical invocation :
h = get a Tag(); // get a tag handler, perhaps from pool
h.setPageContext(pc); // initialize as desired
h.setParent(null);
h.setFoo("foo");

// tag invocation protocol; see Tag.java
try {
doStartTag()...
....
doEndTag()...
} catch (Throwable t) {
// react to exceptional condition
h.doCatch(t);
} finally {
// restore data invariants and release per-invocation resources
h.doFinally();
}
Here we see that if any of the doStartTag(), doInitBody(), doAfterBody() or doEndTag() throws any exception and if you have implemented TryCatchFinally, you will recover from failure and will continue with page execution.
Just thought will let people know why the phenomenon you saw was actually happening.
-Rohit

Originally posted by Madhav Lakkapragada:
When you are writing a custom tag, you can implement TryCatchFinally interface.
When you choose to do this, if the doStartTag() method throws an exception, the doEndTag() method is NOT called. The flow goes to doCatch( ) method, maybe expected right!.
However, if you choose to return "SKIP_PAGE" in the doEndTag( ), you should realize that the page is NOT skipped in the above scenario (since we never went into the doEndTag() ) and that the evaluation of the page continues.
I din't realize this till I played with a real example. Just thought I would pass this along, then again its me.
Learned something new today!!!
regds.
- satya
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic