Spicefactory Forum Index Spicefactory
Discuss Spicefactory Open Source Projects
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Why Are Exceptions behind MessageHandler Code Swallowed?

 
Post new topic   Reply to topic    Spicefactory Forum Index -> Spicefactory - General Discussions
View previous topic :: View next topic  
Author Message
alexuhlmann



Joined: 15 Sep 2009
Posts: 7

PostPosted: Tue Sep 15, 2009 6:31 pm    Post subject: Why Are Exceptions behind MessageHandler Code Swallowed? Reply with quote

In DefaultMessageProcessor, I see:

Code:

   private function invokeMessageTarget (target:MessageTarget) : void {
      try {
         target.handleMessage(this);
      }
      catch (e:Error) {
         log.error("Message Target threw Error {0}", e);
      }
   }


So, every exception from application code executing behind a method marked with MessageHandler will be swallowed and only logged . What is the motivation behind this general try/catch blog?
Back to top
View user's profile Send private message
Jens Halm
Site Admin


Joined: 21 Sep 2007
Posts: 1498
Location: Cologne Germany

PostPosted: Tue Sep 15, 2009 7:14 pm    Post subject: Reply with quote

Well, the original motivation was that one handler should not necessarily be influenced by another failing handler. But it is indeed desirable that developers have more control over error handling. Thus for 2.1 this enhancement ticket already exists:

http://opensource.powerflasher.com/jira/browse/PSL-260

Just happen to work on that right now... Smile
_________________
Jens Halm
Spicefactory
Back to top
View user's profile Send private message
alexuhlmann



Joined: 15 Sep 2009
Posts: 7

PostPosted: Tue Sep 15, 2009 7:41 pm    Post subject: Reply with quote

Wow, great timing. Wink However, I don't fully understand the motivation for this try/catch.

Your workaround with the MessageError tag would be an improvement but AFAIK, it would also require developers to write a MessageError handler for each MessageHandler, wouldn't it? At least, then they are certain that they see exceptions thrown and don't have to watch log files.

What is the extra significance of ensuring other message handlers are executed even if one message handler throws an exception that should alert the developer? Could the developer concerned about handling code, not write their own try/catch behind a MessageHandler?
Back to top
View user's profile Send private message
Jens Halm
Site Admin


Joined: 21 Sep 2007
Posts: 1498
Location: Cologne Germany

PostPosted: Tue Sep 15, 2009 7:55 pm    Post subject: Reply with quote

No, you don't have to write millions of error handlers, you can match any way you want:

Code:
[MessageError (type="com.foo.MyMessage")]
public function handleError (processor:MessageProcessor, error:IOError) : void;

In the first example the error handler would be invoked whenever any handler for a message of type MyMessage throws an IOError.

Code:
[MessageError]
public function handleError (processor:MessageProcessor, error:Error) : void;

But now you really have a global handler, for every type of error in any type of handler. This should give you enough flexibility.

I currently see no alternative. Simply letting the Error through wouldn't be an option. Since message handling could happen asynchronously it could be thrown at unexpected places and developers would have even less control. Or did you have something specific on your mind as a solution?
_________________
Jens Halm
Spicefactory
Back to top
View user's profile Send private message
alexuhlmann



Joined: 15 Sep 2009
Posts: 7

PostPosted: Thu Sep 17, 2009 9:02 am    Post subject: Reply with quote

I see now. Your MessageError tag will solve this very well. Thanks for your replies!
Back to top
View user's profile Send private message
verveguy



Joined: 22 Sep 2009
Posts: 30
Location: Raleigh, NC

PostPosted: Tue Sep 22, 2009 5:02 am    Post subject: Turning on error logging Reply with quote

The try/catch/bury behavior is unfortunate in this case, especially for a developer new to parsley trying to figure out how to get things working and adapting older code to fit.

I see your argument, since it's much like the argument Adobe make regarding binding errors: they *mostly* get swallowed, although some do not.

My real problem in this case is that the errors are swallowed *silently*. The log.error() call inside invokeMessageTarget() never produces any output in the default logs, so there's no way for the developer to know that such problems are occurring.

I've been trying to figure out how to change the config to show me these errors in the trace log...with no luck.

If these errors had been logged, it would have saved me some hours poking around and stepping through my code.

Any clues?
Back to top
View user's profile Send private message
verveguy



Joined: 22 Sep 2009
Posts: 30
Location: Raleigh, NC

PostPosted: Tue Sep 22, 2009 5:14 am    Post subject: Of course.... Reply with quote

Of course, the answer is to simply use standard Flex logging to setup a TraceTarget filtering on org.spicefactory.* classes.

Why did I think it would be harder than that? <sigh>
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Spicefactory Forum Index -> Spicefactory - General Discussions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group