You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Daniel M Garland <da...@titanemail.com> on 2005/06/16 10:48:33 UTC

Catching Tapestry Exceptions?

Hi all,

I'm a beginner with the Tapestry framework, but I've read a lot of 
tutorials and Mr. Lewis Ship's book.  One thing that I didn't 
read/understand much about was an effective way of dealing with Tapestry 
exceptions.

For instance I am creating a Tapestry page that creates a property from 
a database, which is used by a number of Image components to obtain the 
asset name. Whenever this property is inadvertently null, this would of 
course cause a runtime exception because the Image component would not 
know what to render.

However, in a production environment, I would never want a user to see 
the Tapestry exception page; I would prefer the image component to do 
nothing. Up to  now, my strategy has been to ensure that the getAsset() 
method never returns null by wrapping it up in another method, testing 
for nulls and then returning a default image .

I'm sure there are some best practices out there on ensuring that I can 
prevent the exception screen reaching users in a production environment- 
can I catch Tapestry runtime errors and have the message channeled into 
a Insert component or even an email?

TIA
Cheers
Dan Garland


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Catching Tapestry Exceptions?

Posted by Douglas Hubler <dh...@pingtel.com>.
Olve Hansen <olve.hansen <at> intermedia.uib.no> writes:

> I have made a class that rethrows exceptions on a list, so that I can
> pass some exceptions on to some servlet filters.
> 
> I overrode the activateErrorPage in BaseEngine:
> protected void activateExceptionPage(IRequestCycle iRequestCycle, 
> 	ResponseOutputStream responseOutputStream, Throwable throwable) 
> 	throws  ServletException {
> 
>   ExceptionRethrower exceptionRethrower = (ExceptionRethrower) 
> 	getBean("exceptionRethrower");
>   exceptionRethrower.checkForRethrow(throwable);
>   super.activateExceptionPage(iRequestCycle, responseOutputStream,
> throwable);
> }
> 
> In this method you could do whatever you want, but if you call the super
> method, the exception page will appear.
> 
> For this to work you would have to make a subclass of BaseEngine.
> 
> What about detecting whether the asset is null, and make an empty asset.
> I thik this would trigger the alt part of the Image comp.

Daniel, 

Depending on what you want to do after catching an exception, I found an
alternative to overriding BaseEngine that allowed normal page flow not to be
disrupted.  That is, I couldn't override BaseEngine because it would return back
to my page leaving form items blank because some portion of the page rewind,
render had been skipped.

So to solve this, I found wrapping my listeners much less disruptive to the
normal Tapestry's page flow.

Source:
http://scm.sipfoundry.org/rep/sipXconfig/main/web/src/org/sipfoundry/sipxconfig/
components/TapestryContext.java

* Class: UserExceptionAdapter - inner class to handle exceptions
* Method: treatUserExceptionAsValidationError - I call this method explicitly
on listeners I want to intercept exceptions on

Page Specification:
http://scm.sipfoundry.org/rep/sipXconfig/main/web/context/WEB-INF/phone/EditPhon
e.page

This method is good only if you want to explicitly control select pages.  
Global exception handling would required BaseEngine as Olve describes.

[BEGIN SHAMELESS JOB POSTING]
My company is looking for a Tapestry, Hibernate, Spring open source developer,
in Boston North area. See http://www.sipfoundry.org, or email me dhubler (at)
pingtel (dot) com.
[END SHAMELESS JOB POSTING]



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Catching Tapestry Exceptions?

Posted by Olve Hansen <ol...@intermedia.uib.no>.
tor, 16,.06.2005 kl. 09.48 +0100, skrev Daniel M Garland:
> Hi all,
> 
> I'm a beginner with the Tapestry framework, but I've read a lot of 
> tutorials and Mr. Lewis Ship's book.  One thing that I didn't 
> read/understand much about was an effective way of dealing with Tapestry 
> exceptions.
> 
> For instance I am creating a Tapestry page that creates a property from 
> a database, which is used by a number of Image components to obtain the 
> asset name. Whenever this property is inadvertently null, this would of 
> course cause a runtime exception because the Image component would not 
> know what to render.
> 
> However, in a production environment, I would never want a user to see 
> the Tapestry exception page; I would prefer the image component to do 
> nothing. Up to  now, my strategy has been to ensure that the getAsset() 
> method never returns null by wrapping it up in another method, testing 
> for nulls and then returning a default image .
> 
> I'm sure there are some best practices out there on ensuring that I can 
> prevent the exception screen reaching users in a production environment- 
> can I catch Tapestry runtime errors and have the message channeled into 
> a Insert component or even an email?
> 
> TIA
> Cheers
> Dan Garland
> 
I have made a class that rethrows exceptions on a list, so that I can
pass some exceptions on to some servlet filters.

I overrode the activateErrorPage in BaseEngine:
protected void activateExceptionPage(IRequestCycle iRequestCycle, 
	ResponseOutputStream responseOutputStream, Throwable throwable) 
	throws  ServletException {

  ExceptionRethrower exceptionRethrower = (ExceptionRethrower) 
	getBean("exceptionRethrower");
  exceptionRethrower.checkForRethrow(throwable);
  super.activateExceptionPage(iRequestCycle, responseOutputStream,
throwable);
}

In this method you could do whatever you want, but if you call the super
method, the exception page will appear.

For this to work you would have to make a subclass of BaseEngine.

What about detecting whether the asset is null, and make an empty asset.
I thik this would trigger the alt part of the Image comp.

HTH

-- 
Olve Hansen


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Catching Tapestry Exceptions?

Posted by Olve Hansen <ol...@intermedia.uib.no>.
tor, 16,.06.2005 kl. 09.48 +0100, skrev Daniel M Garland:
> Hi all,
> 
> I'm a beginner with the Tapestry framework, but I've read a lot of 
> tutorials and Mr. Lewis Ship's book.  One thing that I didn't 
> read/understand much about was an effective way of dealing with Tapestry 
> exceptions.
> 
> For instance I am creating a Tapestry page that creates a property from 
> a database, which is used by a number of Image components to obtain the 
> asset name. Whenever this property is inadvertently null, this would of 
> course cause a runtime exception because the Image component would not 
> know what to render.
> 
> However, in a production environment, I would never want a user to see 
> the Tapestry exception page; I would prefer the image component to do 
> nothing. Up to  now, my strategy has been to ensure that the getAsset() 
> method never returns null by wrapping it up in another method, testing 
> for nulls and then returning a default image .
> 
> I'm sure there are some best practices out there on ensuring that I can 
> prevent the exception screen reaching users in a production environment- 
> can I catch Tapestry runtime errors and have the message channeled into 
> a Insert component or even an email?
> 
> TIA
> Cheers
> Dan Garland
> 
I have made a class that rethrows exceptions on a list, so that I can
pass some exceptions on to some servlet filters.

I overrode the activateErrorPage in BaseEngine:
protected void activateExceptionPage(IRequestCycle iRequestCycle, 
	ResponseOutputStream responseOutputStream, Throwable throwable) 
	throws  ServletException {

  ExceptionRethrower exceptionRethrower = (ExceptionRethrower) 
	getBean("exceptionRethrower");
  exceptionRethrower.checkForRethrow(throwable);
  super.activateExceptionPage(iRequestCycle, responseOutputStream,
throwable);
}

In this method you could do whatever you want, but if you call the super
method, the exception page will appear.

For this to work you would have to make a subclass of BaseEngine.

What about detecting whether the asset is null, and make an empty asset.
I thik this would trigger the alt part of the Image comp.

HTH

-- 
Olve Hansen



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org