I have several custom exception created in Java. I have connected java with Flex using BlazeDs. Now I need to use those custom exceptions in Flex. How can I do that? In fact, I am trying to call methods in java throwing those custom exception in Flex.
Asked
Active
Viewed 541 times
0
-
Flex will receive whatever is returned from the Java method. However, exceptions will interrupt normal flow of execution, and often throwing an exception will receive no response. Unless you catch that exception in Java and return some special "Exception" object to Flex. – JeffryHouser Jun 25 '12 at 16:52
-
If you are yousing sprin-blazeds integraion look into this [link] http://www.margelatu.org/2009/06/15/meaningful-exceptions-in-lcdsblazeds-applications-using-spring-blazeds-integration/ [/link] – Suave Nti Jun 25 '12 at 17:05
2 Answers
0
Normally when making remoting calls, you listen for ResultEvent
s, which contain the data that was sent by the service. However, if the server throws an error, this will result in a FaultEvent being dispatched. That event contains the information of the original Java exception.
So for instance we could call the service like this:
var token:AsyncToken = myRemoteObject.myMethod();
token.addResponder(new Responder(handleResult, handleFault));
private function handleFault(event:FaultEvent):Function {
trace(event.fault.rootCause);
}

RIAstar
- 11,912
- 20
- 37
-
I haven't dealt with Java, however I thought FaultEvents only fired when there was a problem with the connection such as a cross domain related issue? How would Flex know the difference between a return value that is an exception and one that is a success? – JeffryHouser Jun 25 '12 at 17:54
-
@www.Flextras.com Sorry, I don't know how it does. I just know that it does, at least with Java / BlazeDS. – RIAstar Jun 25 '12 at 18:49
-
@Flextras It's a fairly simple mechanism: The BlazeDS channel endpoint catches runtime Java exceptions and thus always returns a valid response - the exception information is encapsulated within it. On the AS side, the info is decoded and a FaultEvent is dispatched, if the response contained any errors. – weltraumpirat Jun 25 '12 at 20:34
-
What's a bit annoying, though, is that the fault codes and exception messages are stored in different data fields within the FaultEvent, depending on where and when the exception occurred. So you might get a FaultEvent, but `event.fault.rootCause` could contain `null`. Make sure you verify the data for particular exceptions you want to react on. – weltraumpirat Jun 25 '12 at 20:37
0
If your custom exceptions created in Java extend RunTimeException class then you can simply throw them from you java side code. They will be hitting the relevant fault handler. You can check out the following: Link1 and Link2.

akhil_mittal
- 23,309
- 7
- 96
- 95