Google Answers Logo
View Question
 
Q: how do I catch an application exception thrown by an ejb on jboss-4.0? ( No Answer,   0 Comments )
Question  
Subject: how do I catch an application exception thrown by an ejb on jboss-4.0?
Category: Computers > Programming
Asked by: sfqb8-ga
List Price: $20.00
Posted: 29 Jun 2005 18:22 PDT
Expires: 03 Jul 2005 17:47 PDT
Question ID: 538570
I was writing a cactus unit test to test the methods on a stateless
session bean.  Everything was deployed on Jboss version 4.0.2.  In a
test case where I would like to test an application exception
condition, the test code was not able to catch the application
exception, but jboss would throw an org.jboss.util.NestedError where
the nested error was my application exception.

The code looks like this:
public class MySessionBean implements javax.ejb.SessionBean {
  ... all the ejb lifecycle methods...

  public void foo() throws MyException {
    throw new MyException();
  }
}

in the cactus test class:
public class MyCactusTest extends org.apache.cactus.ServletTestCase {
  ... all the methods required by cactus, e.g. constructor, setUp(),  
tearDown()...
  
  public void testFoo() {
    try {
      mySessionBean.foo();
      fail("MyException should be thrown.");
    } catch (MyException e) {
      //ok
      return;
    }
  }
}

when I ran the test, it would fail with output like:
2005-06-29 17:39:28,745 ERROR [org.jboss.ejb.plugins.LogInterceptor]
Unexpected Error in method: public abstract void MySession.foo()
throws MyException

org.jboss.util.NestedError: Unexpected Throwable; - nested throwable:
MyException: //error message and a stack trace

How can I catch MyException in the cactus test?  I assume the same
behavior will happen in the web tier, ie. if I have code in the web
tier calling MySession ejb, the code won't be able to catch
application exception.  Why is my application exception wrapped inside
a org.jboss.util.NestedError?

I want to be able to catch the application exception.
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy