4 Replies Latest reply on Sep 17, 2008 7:55 AM by Amit Purohit

    How do I print the stack trace?

    Tom Nichols Newbie

      So hopefully this will be an easy one --


      I want to print out the exception details on my error.xhml page.  So I need access to the original exception.  Using this page as a reference, I thought I could add a bit in my error.xhtml like so:


      <h:inputTextarea styleClass='stackTrace' value='#{errorHandler.stackTrace}' />
      



      And then have a backing Seam bean:


      @Name("errorHandler") @Scope(ScopeType.PAGE)
      public class ErrorHandlerImpl implements ErrorHandler {
      
           //@In("org.jboss.seam.handledException")
           @In("org.jboss.seam.exception")
           private Exception error;  
           
           @Override
           public String getStackTrace() {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                error.printStackTrace( new PrintStream(out,true) );
                error = null;
                return out.toString();
           }
      }
      
      



      But whenever this gets called, I get the @In attribute requires non-null value -- the bijected field (error) is always null. 


      Likewise, if I try to access the exception or handledException straight from my template, I get a similar error:


      <h:inputTextarea styleClass='stackTrace' value='#{org.jboss.seam.exception.message}' />



      Produces:


      javax.el.PropertyNotFoundException: /error.xhtml @32,92 value="#{org.jboss.seam.exception.message}": Property 'message' not found on type org.jboss.seam.Namespace



      What am I doing wrong?  Do I have to eschew Seam's error handling and resort to something similar to how MyFaces handles errors?


      Thanks in advance.

        • 1. Re: How do I print the stack trace?
          James Kelly Newbie

          Hm. I added this code to my error.xhtml and ginned up a bogus RuntimeException in one of my action handlers. It worked fine.


            <h:outputText value="org.jboss.seam.exception.class = #{org.jboss.seam.exception.class}" />
            <hr/>
          
            <h:outputText value="org.jboss.seam.handledException.class = #{org.jboss.seam.handledException.class}" />
            <hr/>
          
            <h:outputText value="org.jboss.seam.exception.message = #{org.jboss.seam.exception.message}" />
            <hr/>
          
            <h:outputText value="org.jboss.seam.handledException = #{org.jboss.seam.handledException}" />
            <hr/>
          
            <h:outputText value="org.jboss.seam.exception.rootCause = #{org.jboss.seam.exception.rootCause}" />
            <hr/>
          
            <ol>
             <ui:repeat var="ex" value="#{org.jboss.seam.exception.rootCause.stackTrace}">
              <li>
               <h:outputText value="#{ex.className}:#{ex.lineNumber} #{ex.methodName}" />
              </li>
             </ui:repeat>
            </ol>
          



          I'm assuming you've disabled Facelets development mode and Seam debug mode. What exception are you throwing from your application and what does your pages.xml look like?


          • 2. Re: How do I print the stack trace?
            Gavin King Master

            Eeek, thats a bug in Seam2, my fault. We have a package named org.jboss.seam.exception, and we also try to use that as the name for the exception. We need to change that context variable name (to  org.jboss.seam.exception.caughtException, I suggest). I'll create an issue in JIRA.

            • 4. Re: How do I print the stack trace?
              Amit Purohit Newbie
              Hi,
              I am getting the same issue as Tom while using Seam managed exception handling. Following jsf component (in my error page)
              <h:outputText value="org.jboss.seam.handledException.stacktrace = #{org.jboss.seam.handledException,stacktrace}" />
                <hr/>

              prints the exception stacktrace when I redirect the user to the error page in case of any exception thrown in my application. However, when I try to refresh this error page, I get a property not found error for handlexception on
              or.jboss.seam.Namespace.

              I looked at the issue raised in jira, but there seems to be no resolution for the same.

              Can you suggest me some other manner in which I can use features provided by Seam to print the exception stack trace and other information on my error page ?

              Any help really appreciated