Update: it seems that only Java exceptions that directly inherit from RuntimeException get correctly deserialized on Flex side. I suppose this is the expected behavior ? Anybody can confirm ?
Ok, I finally found the answer to my problem. For those interested, the cast of java Exceptions into ActionScript Exception is working exactly like any other class. It has nothing to do with whether the java class extends RuntimeException or not, or any other class / interface. It just doesn't matter at all. Flex RPC simply looks for an AS class mapped to the received Java class through the [RemoteClass] metadata tag. If it finds it, it just try to map fields from java object to AS object (even if a field is not matching, it just ignores it).
So the problem was a very well-know AS compiler problem: AS classes that are used only at runtime for conversion are not compiled in the SWF. In other words, if you have not any class that references your Exception class, that one won't be included in the SWF file, so the RemoteObject won't find it, thus returns an Object instead of strongly typed AS class.
Hope this may help someone
Glad you were able to figure it out and thanks for sharing the solution.
So the problem was a very well-know AS compiler problem: AS classes that are used only at runtime for conversion are not compiled in the SWF.
Strictly speaking, I think this is a method of optimizing SWF size rather than a compiler problem. However, this is a prime example of premature optimization being the root of all evil. I think this has caused me more headaches than all other ActionScript problems combined.
Yes, and also it only works for concrete subclasses, not supertypes!
For example, I just tried to get all Spring Security AuthenticationException classes to map to a class of the same name in Flex, so that I could check on that type. Doesn't work.
Now that I have a class dedicated to the actual CredentialsExpiredException it works.