5 Replies Latest reply on Mar 9, 2008 4:57 PM by cpopetz

    pages.xml adding <action> or <raise-event> in <exception> block

    gonzalad

      Hello,


      There's no way with Seam 2.0.0 to execute an action or raise an event whenever an exception is thrown (otherwise I'm missing sthing once more ;)).


      Wouldnt' it be interesting to allow 'action' and 'raise-event'  ?


      <exception class="MyException">
           <action execute="#{myAction.myMethod}"/>
           <raise-event type="event1"/>
           <end-conversation/>
        <redirect view-id="/error.jspx">
            <message severity="error">XXX</message>
        </redirect>
      </exception>


        • 1. Re: pages.xml adding <action> or <raise-event> in <exception> block
          christian.bauer

          Absolutely not, the system is in an unknown state after an exception and there is no way that you could guarantee anything at that point.

          • 2. Re: pages.xml adding <action> or <raise-event> in <exception> block
            keithnaas

            Sounds like a great phrase to add to the seam docs


            When an exception is handled, the only thing you can guarantee is that the system is in an unknown state


            :)


            • 3. Re: pages.xml adding <action> or <raise-event> in <exception> block
              gonzalad

              Thanks for the answer.


              I was just wondering if I want to trace the erreur myself (like storing a record in the database whenever this error happens), how could I do this without this kind of feature ?


              I don't have this need right now, was asking for curiosity.


              Thanks once more !

              • 4. Re: pages.xml adding <action> or <raise-event> in <exception> block
                christian.bauer

                Well, the answer is You do not store it in a database. What if the exception was database is down? The whole point of a RuntimeException (and that is what we are talking about here) is that your thread of execution is dead if it occurs.


                Write a custom LogAppender for Log4j or something.

                • 5. Re: pages.xml adding <action> or <raise-event> in <exception> block
                  cpopetz

                  Gonzalez Adrian wrote on Mar 06, 2008 04:05 PM:


                  Thanks for the answer.

                  I was just wondering if I want to trace the erreur myself (like storing a record in the database whenever this error happens), how could I do this without this kind of feature ?

                  I don't have this need right now, was asking for curiosity.

                  Thanks once more !


                  While I agree with Christian's warnings about the system being in a bad state at the time an exception is unhandled, we successfully log all unhandled exceptions to a db, but we use a separate database/data source/ entityManager to ensure that it's mainly independent of whatever happened in the main conversation.


                  But, unfortunately, there's no clean way to execute an action on the global case of an unhandled error, so we do the following:


                  import org.jboss.seam.exception.Exceptions;
                  
                  @Scope(ScopeType.APPLICATION)
                  @Name("org.jboss.seam.exception.exceptions")
                  public class MyErrorHandler extends Exceptions {
                  
                       @Create
                       public void initialize() throws Exception  { super.initialize(); }
                       
                       public void handle (Exception e) throws Exception {
                            try { 
                                 super.handle(e);
                                 return;
                            }
                            catch (Exception rethrown) { 
                                 //do our custom error handling here
                            }
                       }