<commit_before>package org.specs

object ExtendedThrowable {
  implicit def toExtendedThrowable(t: Throwable) = new ExtendedThrowable(t)
  class ExtendedThrowable(t: Throwable) {
    def location: String = (t.getStackTrace()(0).getFileName + ":" + t.getStackTrace()(0).getLineNumber)
    
    /**
     * Throws an exception removing the traces of the object wanting to throw this exception
     * @param origin object which has be called to throw the <code>Exception</code> 
     * @param exception the exception to throw 
     */
    def rethrowFrom(origin: Object) = {
      setStackTrace(t, t, origin.getClass.getName.split("\\.").last)
      throw t
    }
    def rethrowFrom(origin: Object, other: Throwable) = {
      setStackTrace(other, t, origin.getClass.getName.split("\\.").last)
      throw other
    }
    def setStackTrace(other: Throwable, t: Throwable, name: String) = other.setStackTrace((t.getStackTrace.toList.drop(1).dropWhile {x: StackTraceElement => x.toString.matches(".*" + name + ".*") }).toArray) 
  }
}<commit_msg>added a doc for ExtendedThrowable<commit_after>package org.specs

/**
 * This object allows to add some utility methods to </code>Throwable</code> objects.
 */
object ExtendedThrowable {
  implicit def toExtendedThrowable(t: Throwable) = new ExtendedThrowable(t)
  
  /**
 	 * See the ExtendedThrowable object description
 	 */
  class ExtendedThrowable(t: Throwable) {
    /** @return the file name and the line number where the Throwable was created */
    def location: String = (t.getStackTrace()(0).getFileName + ":" + t.getStackTrace()(0).getLineNumber)
    
    /**
     * throws an exception removing the traces of the object wanting to throw this exception
     * @param origin object which has be called to throw the <code>Exception</code> 
     * @param exception the exception to throw 
     */
    def rethrowFrom(origin: Object) = {
      setStackTrace(t, t, origin.getClass.getName.split("\\.").last)
      throw t
    }
    
    /**
     * throws this exception as another type of exception, removing the lines where <code>origin</code> occurs 
     */
    def rethrowFrom(origin: Object, other: Throwable) = {
      setStackTrace(other, t, origin.getClass.getName.split("\\.").last)
      throw other
    }

    /** 
     * sets the stacktrace of <code>other</code> with the stacktrace of <code>t</code> removing the first line (the original location)
     * and then all lines matching <code>name</code>
     */
    def setStackTrace(other: Throwable, t: Throwable, name: String) = {
      other.setStackTrace((t.getStackTrace.toList.drop(1).dropWhile { x: StackTraceElement => 
                             x.toString.matches(".*" + name + ".*") 
                          }).toArray) 
    }
  }
}
{'fraction_non_alphanumeric': 0.1215088864708016, 'fraction_numerical': 0.002176278563656148, 'mean_word_length': 3.073855243722304, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5037572', 'n_tokens_mistral': 802, 'n_tokens_neox': 779, 'n_words': 230}