Changeset 10586 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2016-07-22T22:30:54+02:00 (9 years ago)
- 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 20 20 * 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 21 21 * 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. 23 24 * <pre> 24 25 * int id = ...; … … 27 28 * ... your code ... 28 29 * } 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()); 30 31 * } 31 32 * </pre> 32 33 * 33 34 * 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 ex ecption or ignore it.35 * the exception or ignore it. 35 36 * 36 37 * @author Michael Zangl -
trunk/src/org/openstreetmap/josm/tools/bugreport/ReportedException.java
r10585 r10586 17 17 import java.util.NoSuchElementException; 18 18 import java.util.Set; 19 import java.util.function.Supplier; 19 20 20 21 import org.openstreetmap.josm.Main; … … 180 181 181 182 /** 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. 183 184 * 184 185 * @param key … … 189 190 */ 190 191 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) { 191 206 String string; 192 207 try { 208 Object value = valueSupplier.get(); 193 209 if (value == null) { 194 210 string = "null";
Note:
See TracChangeset
for help on using the changeset viewer.