Class ReportedException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- org.openstreetmap.josm.tools.bugreport.ReportedException
-
- All Implemented Interfaces:
java.io.Serializable
public class ReportedException extends java.lang.RuntimeException
This is a special exception that cannot be directly thrown.It is used to capture more information about an exception that was already thrown.
- Since:
- 10285
- See Also:
BugReport, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classReportedException.CauseTraceIteratorIterates over the causes for this exception.private static classReportedException.Sectionprivate static classReportedException.SectionEntry
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Thread,java.lang.StackTraceElement[]>allStackTracesWe capture all stack traces on exception creation.private java.lang.ThreadcaughtOnThreadprivate static intMAX_COLLECTION_ENTRIESHow many entries of a collection to include in the bug report.private java.lang.StringmethodWarningFromprivate java.util.LinkedList<ReportedException.Section>sectionsprivate static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description ReportedException(java.lang.Throwable exception)Constructs a newReportedException.ReportedException(java.lang.Throwable exception, java.lang.Thread caughtOnThread)Constructs a newReportedException.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static booleanhasSameStackTrace(ReportedException.CauseTraceIterator causeTraceIterator, java.lang.Throwable e2)booleanisOutOfMemory()Check if this is caused by an out of memory situationbooleanisSame(ReportedException e)Checks if this exception is considered the same as an other exception.private static java.lang.StringmakeCollectionNice(java.util.Collection<?> value)booleanmayHaveConcurrentSource()Check if this exception may be caused by a threading issue.private static java.lang.StringniceThreadName(java.lang.Thread thread)voidprintReportDataTo(java.io.PrintWriter out)Prints the captured data of this report to aPrintWriter.voidprintReportStackTo(java.io.PrintWriter out)Prints the stack trace of this report to aPrintWriter.voidprintReportThreadsTo(java.io.PrintWriter out)Prints the stack traces for other threads of this report to aPrintWriter.ReportedExceptionput(java.lang.String key, java.lang.Object value)Adds some debug values to this exception.ReportedExceptionput(java.lang.String key, java.util.function.Supplier<java.lang.Object> valueSupplier)Adds some debug values to this exception.voidstartSection(java.lang.String sectionName)Starts a new debug data section.java.lang.StringtoString()voidwarn()Displays a warning for this exception.
-
-
-
Field Detail
-
MAX_COLLECTION_ENTRIES
private static final int MAX_COLLECTION_ENTRIES
How many entries of a collection to include in the bug report.- See Also:
- Constant Field Values
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
allStackTraces
private final transient java.util.Map<java.lang.Thread,java.lang.StackTraceElement[]> allStackTraces
We capture all stack traces on exception creation. This allows us to trace synchronization problems better. We cannot be really sure what happened but we at least see which threads
-
sections
private final java.util.LinkedList<ReportedException.Section> sections
-
caughtOnThread
private final transient java.lang.Thread caughtOnThread
-
methodWarningFrom
private java.lang.String methodWarningFrom
-
-
Constructor Detail
-
ReportedException
public ReportedException(java.lang.Throwable exception)
Constructs a newReportedException.- Parameters:
exception- the cause (which is saved for later retrieval by theThrowable.getCause()method)- Since:
- 14380
-
ReportedException
public ReportedException(java.lang.Throwable exception, java.lang.Thread caughtOnThread)
Constructs a newReportedException.- Parameters:
exception- the cause (which is saved for later retrieval by theThrowable.getCause()method)caughtOnThread- thread where the exception was caught- Since:
- 14380
-
-
Method Detail
-
warn
public void warn()
Displays a warning for this exception. The program can then continue normally. Does not block.
-
startSection
public void startSection(java.lang.String sectionName)
Starts a new debug data section. This normally does not need to be called manually.- Parameters:
sectionName- The section name.
-
printReportDataTo
public void printReportDataTo(java.io.PrintWriter out)
Prints the captured data of this report to aPrintWriter.- Parameters:
out- The writer to print to.
-
printReportStackTo
public void printReportStackTo(java.io.PrintWriter out)
Prints the stack trace of this report to aPrintWriter.- Parameters:
out- The writer to print to.
-
printReportThreadsTo
public void printReportThreadsTo(java.io.PrintWriter out)
Prints the stack traces for other threads of this report to aPrintWriter.- Parameters:
out- The writer to print to.
-
niceThreadName
private static java.lang.String niceThreadName(java.lang.Thread thread)
-
isSame
public boolean isSame(ReportedException e)
Checks if this exception is considered the same as an other exception. This is the case if both have the same cause and message.- Parameters:
e- The exception to check against.- Returns:
trueif they are considered the same.
-
hasSameStackTrace
private static boolean hasSameStackTrace(ReportedException.CauseTraceIterator causeTraceIterator, java.lang.Throwable e2)
-
put
public ReportedException put(java.lang.String key, java.lang.Object value)
Adds some debug values to this exception. The value is converted to a string. Errors during conversion are handled.- Parameters:
key- The key to add this for. Does not need to be unique but it would be nice.value- The value.- Returns:
- This exception for easy chaining.
-
put
public ReportedException put(java.lang.String key, java.util.function.Supplier<java.lang.Object> valueSupplier)
Adds some debug values to this exception. This method automatically catches errors that occur during the production of the value.- Parameters:
key- The key to add this for. Does not need to be unique but it would be nice.valueSupplier- A supplier that is called once to get the value.- Returns:
- This exception for easy chaining.
- Since:
- 10586
-
makeCollectionNice
private static java.lang.String makeCollectionNice(java.util.Collection<?> value)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Throwable
-
mayHaveConcurrentSource
public boolean mayHaveConcurrentSource()
Check if this exception may be caused by a threading issue.- Returns:
trueif it is.- Since:
- 10585
-
isOutOfMemory
public boolean isOutOfMemory()
Check if this is caused by an out of memory situation- Returns:
trueif it is.- Since:
- 10819
-
-