Ignore:
Timestamp:
2016-07-22T22:30:54+02:00 (8 years ago)
Author:
Don-vip
Message:

see #11390, fix #13190 - Allow Lambda bug report parameters (patch by michael2402) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm/tools/bugreport
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/bugreport/BugReport.java

    r10585 r10586  
    2020 * You should then add some debug information there. This can be the OSM ids that caused the error, information on the data you were working on
    2121 * or other local variables. Make sure that no excpetions may occur while computing the values. It is best to send plain local variables to
    22  * put(...). Then simply throw the throwable you got from the bug report. The global exception handler will do the rest.
     22 * put(...). If you need to do computations, put them into a lambda expression. Then simply throw the throwable you got from the bug report.
     23 * The global exception handler will do the rest.
    2324 * <pre>
    2425 * int id = ...;
     
    2728 *   ... your code ...
    2829 * } catch (RuntimeException t) {
    29  *   throw BugReport.intercept(t).put("id", id).put("tag", tag);
     30 *   throw BugReport.intercept(t).put("id", id).put("tag", () -> x.getTag());
    3031 * }
    3132 * </pre>
    3233 *
    3334 * Instead of re-throwing, you can call {@link ReportedException#warn()}. This will display a warning to the user and allow it to either report
    34  * the execption or ignore it.
     35 * the exception or ignore it.
    3536 *
    3637 * @author Michael Zangl
  • trunk/src/org/openstreetmap/josm/tools/bugreport/ReportedException.java

    r10585 r10586  
    1717import java.util.NoSuchElementException;
    1818import java.util.Set;
     19import java.util.function.Supplier;
    1920
    2021import org.openstreetmap.josm.Main;
     
    180181
    181182    /**
    182      * Adds some debug values to this exception.
     183     * Adds some debug values to this exception. The value is converted to a string. Errors during conversion are handled.
    183184     *
    184185     * @param key
     
    189190     */
    190191    public ReportedException put(String key, Object value) {
     192        return put(key, () -> value);
     193    }
     194
     195    /**
     196    * Adds some debug values to this exception. This method automatically catches errors that occur during the production of the value.
     197    *
     198    * @param key
     199    *            The key to add this for. Does not need to be unique but it would be nice.
     200    * @param valueSupplier
     201    *            A supplier that is called once to get the value.
     202    * @return This exception for easy chaining.
     203    * @since 10586
     204    */
     205    public ReportedException put(String key, Supplier<Object> valueSupplier) {
    191206        String string;
    192207        try {
     208            Object value = valueSupplier.get();
    193209            if (value == null) {
    194210                string = "null";
Note: See TracChangeset for help on using the changeset viewer.