How to pop up an error dialog in Scene when an error occurs in javaFX?

I have a code that when deleting a non-existent element in an array throws an error. And I want to draw some kind of error dialog box when throwing this error. I’m a bit confused on how to implement this in JavaFX

public static JMXMessage getMessage(QueueControl queueControl) {
 JMXHeaders jmxHeaders;
 JMXMessage jmxMessage;
 String body;
 String replyTo = null;
 String correlationId = null;
 try {
  CompositeData[] messages = queueControl.browse();
  j = queueLength - i;
  if (j > queueLength - 1) {
   i = 1;
   j = queueLength - i;
  if (j < 0) {
  i = queueLength;
  j = 0;

 TabularData stringProps = (TabularData) messages[j].get(CompositeDataConstants.STRING_PROPERTIES);
 for (CompositeData o : (Collection<CompositeData>) stringProps.values()) {
  Object key = o.get("key");
   if (key.equals("JMSReplyTo")) {
    replyTo = o.get("value").toString();
  if (key.equals("JMSCorrelationID")) {
 correlationId = o.get("value").toString();
 jmxHeaders = new JMXHeaders(messages[j].get(CompositeDataConstants.TYPE).toString(),

 body = (String) messages[j].get(CompositeDataConstants.TEXT_BODY);
 jmxMessage = new JMXMessage(jmxHeaders, body);
 queueLength = queueControl.browse().length;
 return BuildGet.serializationAndDeserializationMessage(jmxMessage);
 } catch (Exception e) {
 throw new RuntimeException(e);

I don’t understand how to display an error window when an error occurs

>Solution :

if what you mean is to pop up an alert to the user, you can use JOptionPane in that, and put it in the catch section.
you can implement it like that:

JOptionPane.showMessageDialog(null, "the message you want to pop up");

Leave a Reply