class ErrorDialog extends Dialog {

  @VisibleForTesting
  protected void handleException( String message, Exception exception, StringBuilder text, StringBuilder details ) {
    if ( exception instanceof KettleException ) {
      // Normal error
      KettleException ke = (KettleException) exception;
      Throwable cause = ke.getCause();
      if ( cause != null && cause.getMessage() != null ) {
        text.append( cause.getMessage() );
      } else {
        text.append( ke.getMessage() );
      }

    } else if ( exception instanceof InvocationTargetException ) {
      // Error from somewhere else, what is the cause?
      Throwable cause = exception.getCause();
      if ( cause instanceof KettleException ) {
        KettleException ke = (KettleException) cause;
        text.append( ke.getMessage() );
      } else {
        text.append( Const.NVL( cause.getMessage(), cause.toString() ) );
        while ( text.length() == 0 && cause != null ) {
          cause = cause.getCause();
          if ( cause != null ) {
            text.append( Const.NVL( cause.getMessage(), cause.toString() ) );
          }
        }
      }
    } else {
      // Error from somewhere else...

      if ( exception.getMessage() == null ) {
        text.append( message );
      } else {
        text.append( exception.getMessage() );
      }
    }

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter( sw );
    exception.printStackTrace( pw );

    details.append( sw.getBuffer() );
  }

  public  ErrorDialog( Shell parent, String title, String message, Throwable throwable );
  public  ErrorDialog( Shell parent, String title, String message, Exception exception );
  public  ErrorDialog( Shell parent, String title, String message, Exception exception, boolean showCancelButton );

}