serialize Throwable : Exception « Development « Android

Home
Android
1.2D Graphics
2.Animation
3.Core Class
4.Database
5.Date Type
6.Development
7.File
8.Game
9.Hardware
10.Media
11.Network
12.Security
13.UI
14.User Event
Android » Development » Exception 
serialize Throwable
    
//package crowdedroom.hop4droid;

import static java.text.MessageFormat.format;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * The Class Util.
 */
public class Util {

  /**
   * Serialize throwable.
   @param throwable the throwable
   @return the string
   */
  public static String serializeThrowable(final Throwable throwable) {
    final StringBuilder builder = new StringBuilder();
    builder.append("<?xml version=\"1.0\"?>");
    builder.append("<error>");
    builder.append("<class>"
      + throwable.getClass().getName()
      "</class>");
    builder.append("<message>"
      + throwable.getMessage()
      "</message>");
    builder.append("<backtrace>");
    for (final StackTraceElement element : throwable.getStackTrace()) {
      builder.append(format(
        "<line method=\"{0}.{1}\" file=\"{2}\" number=\"{3}\"/>",
        element.getClassName(),
        element.getFileName(),
        element.getLineNumber(),
        element.getMethodName()));
    }
    builder.append("</backtrace>");
    builder.append("</error>");
    builder
      .append("<server-environment><project-root>/root</project-root><environment-name>env</environment-name></server-environment>");
    builder.append("</notice>");
    return builder.toString();
  }
}

   
    
    
    
  
Related examples in the same category
1.dig Message out of Throwable
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.