Package org.yaac.client.util

Source Code of org.yaac.client.util.ExceptionManager

package org.yaac.client.util;

import static com.google.common.base.Strings.isNullOrEmpty;

import javax.inject.Inject;

import org.yaac.client.i18n.ErrorMessages;
import org.yaac.shared.YaacException;


import com.google.gwt.user.client.Window;

/**
* @author Max Zhu (thebbsky@gmail.com)
*
*/
public class ExceptionManager {

  private final ErrorMessages errorMsg;
 
  @Inject
  ExceptionManager(ErrorMessages errorMsg) {
    super();
    this.errorMsg = errorMsg;
  }

  /**
   * @param caught
   */
  public void handle(Throwable caught) {
    if (caught instanceof YaacException) {
      YaacException e = (YaacException) caught;
     
      if (isNullOrEmpty(e.getErrorCode())) {
        Window.alert(e.getErrorMsg());
      } else {
        String msg = errorMsg.getString(e.getErrorCode());
        Window.alert(msg);
      }
    } else // unexpected exception
      caught.printStackTrace();
      Window.alert("Unexpected exception : " + caught.getMessage());
    }
  }
}
TOP

Related Classes of org.yaac.client.util.ExceptionManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.