Profile Image

What is Java On-Error Command: -XX:OnError?

What is Java On-Error Command:-XX:OnError? Have you used this JVM argument before? What are the pros & cons of using this Java argument? Can you share your perspective/experience in using this JVM argument?

  • jvm-argument

  • xx-onerror

  • x-onerror

  • Java On-Error Command

Please Sign In or to post your comment or answer

Profile Image

Pavel Khodakovsky



• -XX:OnError=<command>


The command parameter may contain the special sequence %p, which is replaced by the process identifier of the JVM process.



The -XX:OnError option allows an operator to specify a command or sequence
of commands to execute when the JVM crashes due to an unrecoverable error.
This can be used for example to generate additional data that could help to
diagnose causes of the crash. Alternatively it could be used to alert the operator
to the crash so that corrective action can be taken (e.g. restarting the process).

The command string can be either a single command, or multiple commands
separated by semicolons. If the command string contains one or more instances
of the special sequence %p then it shall be replaced with the identifier of the
Java process. If the command string contains spaces then it must be surrounded
by quotation marks.



Linux/MacOS example:

java -XX:OnError="gcore %p; echo 'Process %p has crashed.' \
| mail -s 'Java Crash'"
This runs the gcore command to create a core image and then emails to alert them of the crash.
Windows example:

java -XX:OnError="userdump.exe %p"

This runs the userdump.exe utility to generate a dump file (assuming that
userdump.exe is available from the PATH environment variable).

Default Value:
The default value of -XX:OnError is empty, i.e. no action is performed.




Arguments Related to -XX:OnError:

TODO: link to -XX:OnOutOfMemoryError


If you have additional comments, interesting experiences or even point of disagreement with this JVM argument description, please leave a comment. Your
insights will help the entire 10+ million java developer community to develop
one standard source of documentation for all the JVM arguments.

Got something else on mind? Post Your Question

Not the answer you're looking for? Browse other questions tagged
  • jvm-argument

  • xx-onerror

  • x-onerror

  • Java On-Error Command