Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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(),
 messages[j].get(CompositeDataConstants.EXPIRATION).toString(),
 messages[j].get(CompositeDataConstants.DURABLE).toString(),
 replyTo,
 messages[j].get(CompositeDataConstants.MESSAGE_ID).toString(),
 messages[j].get(CompositeDataConstants.TIMESTAMP).toString(),
 correlationId,
 messages[j].get(CompositeDataConstants.PRIORITY).toString());

 body = (String) messages[j].get(CompositeDataConstants.TEXT_BODY);
 jmxMessage = new JMXMessage(jmxHeaders, body);
 queueControl.removeMessage(Long.parseLong(messages[j].get(CompositeDataConstants.MESSAGE_ID).toString()));
 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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading