You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Martijn Hinten <ma...@cumquat.nl> on 2005/11/15 22:42:46 UTC

How to get the name of the page that raised an exception?

I have overridden Tapestry's exceptionPresenter and provided my own 
subclass of org.apache.tapestry.error.ExceptionPresenter. In it's 
presentException method, is there any way to figure out the name of the 
page that raised the exception? I would like to show the exception in a 
friendly way, on the page that raised it.

I noticed that cycle.getPage().getPageName() does not return the name of 
the current page.

Thanks for any hints.



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


Re: How to get the name of the page that raised an exception?

Posted by Leonardo Quijano Vincenzi <le...@dtqsoftware.com>.
This sounds like a hack... what happens if the page class has a 
different name than the template? For example if I had a common page 
class for several different pages, etc.

And besides, this isn't really bullet-proof. There's no guarantee that 
another class or proxy will be between the page and the exception, or 
even that the page is processed at all.

I did put an issue on this, I had the same problem. Check it out, and 
please vote for it. It's fairly easy if we can extend Tapestry's 
PageNotFoundException:

Check:
http://issues.apache.org/jira/browse/TAPESTRY-670


-- 
Ing. Leonardo Quijano Vincenzi
Director Técnico
DTQ Software


Martijn Hinten wrote:
> Thanks Mike! I think I will be able to extract the pagename from my 
> own stack trace, and thus solve my problem.
>
> Thanks again.
>
>
> Mike.Barber@expeditors.com wrote:
>
>> This is something I do to emulate Log4j.  Examine the stack & find 
>> the first entry that does not contain ExceptionInfo as a classname.
>>
>> call displayInfo() in your catch statement, or call displayInfo() 
>> whereever to track class, method, & line number.
>>
>> note: this code is customized for this example, not taken verbatim 
>> from my code....
>>
>>   - Mike Barber



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


Re: How to get the name of the page that raised an exception?

Posted by Martijn Hinten <ma...@cumquat.nl>.
Thanks Mike! I think I will be able to extract the pagename from my own 
stack trace, and thus solve my problem.

Thanks again.


Mike.Barber@expeditors.com wrote:

>This is something I do to emulate Log4j.  Examine the stack & find the 
>first entry that does not contain ExceptionInfo as a classname.
>
>call displayInfo() in your catch statement, or call displayInfo() 
>whereever to track class, method, & line number.
>
>note: this code is customized for this example, not taken verbatim from my 
>code....
>
>   - Mike Barber
>
>
>class ExceptionInfo
>{
>   public void displayInfo()
>   {
>               // setup stack info
>               Throwable t = new Throwable();
>               StackTraceElement[] stackElements = t.getStackTrace();
>               int line = 0;
>               for (int i=0; i<stackElements.length; i++)
>               {
>                  StackTraceElement ste = stackElements[i];
>                  String simpleClassName = 
>_extractSimpleClassName(stackElements[i].getClassName());
>                  // the first line to NOT have this class's name is the 
>line we want
>                  if (simpleClassName != null && 
>!simpleClassName.equals("ExceptionInfo"))
>                  {
>                     line = i;
>                     StackTraceElement steFirst = stackElements[line];
>                     System.out.println(steFirst.toString());
>                     break;
>                  }
>               }
>    }
>
>   private String _extractSimpleClassName(String fullClassName)
>   {
>      if ((null == fullClassName) || ("".equals(fullClassName)))
>         return "";
>
>      int lastDot = fullClassName.lastIndexOf('.');
>      if (0 > lastDot)
>         return fullClassName;
>
>      return fullClassName.substring(++lastDot);
>   }
>}
>
>
>
>
>
>
>Martijn Hinten <ma...@cumquat.nl> 
>11/15/2005 01:42 PM
>Please respond to
>"Tapestry users" <ta...@jakarta.apache.org>
>
>
>To
>Tapestry users <ta...@jakarta.apache.org>
>cc
>
>Subject
>How to get the name of the page that raised an exception?
>
>
>
>
>
>
>I have overridden Tapestry's exceptionPresenter and provided my own 
>subclass of org.apache.tapestry.error.ExceptionPresenter. In it's 
>presentException method, is there any way to figure out the name of the 
>page that raised the exception? I would like to show the exception in a 
>friendly way, on the page that raised it.
>
>I noticed that cycle.getPage().getPageName() does not return the name of 
>the current page.
>
>Thanks for any hints.
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>
>  
>

-- 


*Cumquat Information Technology*
De Dreef 19
3706 BR Zeist
T +31 (0)30 - 6940490
F +31 (0)10 - 6940499
http://www.cumquat.nl <http://www.cumquat.nl/>

martijn.hinten@cumquat.nl <ma...@cumquat.nl>
M +31 6 22 384 318


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


Re: How to get the name of the page that raised an exception?

Posted by Mi...@expeditors.com.
This is something I do to emulate Log4j.  Examine the stack & find the 
first entry that does not contain ExceptionInfo as a classname.

call displayInfo() in your catch statement, or call displayInfo() 
whereever to track class, method, & line number.

note: this code is customized for this example, not taken verbatim from my 
code....

   - Mike Barber


class ExceptionInfo
{
   public void displayInfo()
   {
               // setup stack info
               Throwable t = new Throwable();
               StackTraceElement[] stackElements = t.getStackTrace();
               int line = 0;
               for (int i=0; i<stackElements.length; i++)
               {
                  StackTraceElement ste = stackElements[i];
                  String simpleClassName = 
_extractSimpleClassName(stackElements[i].getClassName());
                  // the first line to NOT have this class's name is the 
line we want
                  if (simpleClassName != null && 
!simpleClassName.equals("ExceptionInfo"))
                  {
                     line = i;
                     StackTraceElement steFirst = stackElements[line];
                     System.out.println(steFirst.toString());
                     break;
                  }
               }
    }

   private String _extractSimpleClassName(String fullClassName)
   {
      if ((null == fullClassName) || ("".equals(fullClassName)))
         return "";

      int lastDot = fullClassName.lastIndexOf('.');
      if (0 > lastDot)
         return fullClassName;

      return fullClassName.substring(++lastDot);
   }
}






Martijn Hinten <ma...@cumquat.nl> 
11/15/2005 01:42 PM
Please respond to
"Tapestry users" <ta...@jakarta.apache.org>


To
Tapestry users <ta...@jakarta.apache.org>
cc

Subject
How to get the name of the page that raised an exception?






I have overridden Tapestry's exceptionPresenter and provided my own 
subclass of org.apache.tapestry.error.ExceptionPresenter. In it's 
presentException method, is there any way to figure out the name of the 
page that raised the exception? I would like to show the exception in a 
friendly way, on the page that raised it.

I noticed that cycle.getPage().getPageName() does not return the name of 
the current page.

Thanks for any hints.



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