The ProtectedCommand offer two protection to the developper. The first is that the developper can use a validateNotificationBody() method to validate the notification body.

The second is that the execute method use a try catch to around the call to a executeSafely method that embbed the command logic.

With these two behaviour decoupled from the application logic, you can more easily implements a coherent error handling.

public class AddSecurityCommand extends ProtectedCommand {

    override public function validateNotificationBody(data : Object) : void {
        assertTrue(data != null, "The notification's body is null");
        assertTrue(data.label != null, "The security label is null");
        assertTrue(data.currencyCode != null, "The currencyCode is null");
        assertTrue(data.isinCode != null, "The isinCode is null");
        assertTrue(data.currencyCode is String, "The currencyCode is not a String " + data["currencyCode"].toString());

    override public function executeSafely(note : INotification) : void {
        /* At this point, we know that the Notification body has pass the
         * validation. We can use it safely. If an error is throwed by this
         * method, it will be trapped by the parent execute method.
        var data : Object = note.getBody();