Android Open Source - EdXVideoViewer Uncaught Exception Logger






From Project

Back to project page EdXVideoViewer.

License

The source code is released under:

MIT License

If you think the Android project EdXVideoViewer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.github.krooken.edxvideoviewer;
// w w  w  .  j  a v a  2 s  . c  o  m
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.Thread.UncaughtExceptionHandler;

public class UncaughtExceptionLogger implements UncaughtExceptionHandler {
  
  private String logFolder;
  private UncaughtExceptionHandler defaultHandler;
  
  public UncaughtExceptionLogger(String logFolder, UncaughtExceptionHandler defaultHandler) {
    this.logFolder = logFolder;
    this.defaultHandler = defaultHandler;
  }

  @Override
  public void uncaughtException(Thread thread, Throwable exception) {
    
    String timestamp = System.currentTimeMillis() + "";
    
    try {
      BufferedWriter writer = new BufferedWriter(new FileWriter(
          logFolder + "/" + timestamp + "-log.txt"));
      PrintWriter printer = new PrintWriter(writer);
      printer.append(exception.getMessage());
      exception.printStackTrace(printer);
      if(exception instanceof UnexpectedHttpResponseException) {
        UnexpectedHttpResponseException uhrEx = (UnexpectedHttpResponseException)exception;
        printer.append(uhrEx.getRequestUrl());
        printer.append(uhrEx.getFormattedHeaders());
        printer.append(uhrEx.getResponse());
      }
      writer.flush();
      writer.close();
      printer.close();
    } catch(IOException ex) {
      ex.printStackTrace();
    }
    
    defaultHandler.uncaughtException(thread, exception);
  }

}




Java Source Code List

com.github.krooken.edxvideoviewer.CourseViewer.java
com.github.krooken.edxvideoviewer.CoursewareContentViewer.java
com.github.krooken.edxvideoviewer.CoursewareSectionViewer.java
com.github.krooken.edxvideoviewer.HttpGetRequest.java
com.github.krooken.edxvideoviewer.LoginScreen.java
com.github.krooken.edxvideoviewer.UncaughtExceptionLogger.java
com.github.krooken.edxvideoviewer.UnexpectedHttpResponseException.java