A simple Java library for helpful exception messages
Feel free to leave an issue or make pull requests
You could use class DefaultProblemBuilder
to build some Problem
and throw it as IllegalArgumentException
or any other
throw DefaultProblemBuilder.newBuilder()
.id(() -> "Example ID, provide ID that will help you to identify a problem")
.what("Test JProblem") //required
.where("Just in main class")
.why("I want to show how to use JProblem")
.documentedAt("https://github.com/xeruvimov/jproblem")
.withLongDescription("Use this field to provide long description of error; you may need to write some context or anything else")
.addSolution("Use JProblem to write code that works as indeed")
.addSolution("Or just ignore this exception")
.cause(e)
.buildAsException(IllegalArgumentException::new);
The code above will produce next exception in console
Exception in thread "main" java.lang.IllegalArgumentException: A problem happened
Problem ID : Example ID, provide ID that will help you to identify a problem
Where? : Just in main class
What? : Test JProblem
Why? : I want to show how to use JProblem
Long description : Use this field to provide long description of error; you may need to write some context or anything else
Possible solutions :
- Use JProblem to write code that works as indeed
- Or just ignore this exception
Documentation link : https://github.com/xeruvimov/jproblem
at io.github.xeruvimov.jproblem.builder.DefaultProblemBuilder.buildAsException(DefaultProblemBuilder.java:91)
at com.skheruvimov.script.ScriptTestProjApp.main(ScriptTestProjApp.java:30)
Caused by: java.lang.RuntimeException: Root cause
at com.skheruvimov.script.ScriptTestProjApp.main(ScriptTestProjApp.java:18)
Only what
field is required, so you also can make small messages
throw DefaultProblemBuilder.newBuilder()
.what("I don't want to force my collegues to read 'War and Peace' in every error case")
.buildAsRuntimeException();
Exception in thread "main" java.lang.RuntimeException: A problem happened
What? : I dont want to force my colleges to read 'War and Peace' in every error cases
at io.github.xeruvimov.jproblem.builder.DefaultProblemBuilder.buildAsRuntimeException(DefaultProblemBuilder.java:72)
at com.skheruvimov.script.ScriptTestProjApp.main(ScriptTestProjApp.java:20)
<dependency>
<groupId>io.github.xeruvimov</groupId>
<artifactId>jproblem</artifactId>
<version>1.0.2</version>
</dependency>
implementation group: 'io.github.xeruvimov', name: 'jproblem', version: '1.0.2'