0

I want to show exception stacktrace as soon as an exception is caught in the catch block. I am referring to the doc for ControlFX here. Do I just need to copy a part of code and paste it inside the catch block to get the dialog open? Please let me know.

 try{

 }
 catch (SQL Exception ex){

  public Action showException(Throwable exception) {
        Dialog dlg = buildDialog(Type.ERROR);
        dlg.setContent(exception.getMessage());
        dlg.setExpandableContent(buildExceptionDetails(exception));
        return dlg.show();
    }


 }

Doing the above generates lot of errors and I am sure something is wrong.

Changes Done After Moving the Code from Catch into Try block are shown in the Image Image:

The error shown in the line #143 above, is as follows despite having imported import org.controlsfx.control.action.Action; import org.controlsfx.dialog.Dialogs;

line #143

ItachiUchiha
  • 36,135
  • 10
  • 122
  • 176
rocky
  • 435
  • 3
  • 8
  • 18

2 Answers2

1

You are declaring a method in a catch block, which is illegal syntax. Declare the showException method outside of the method in which the catch block resides, and simply call the showException from within the catch block.

You are also importing the wrong Dialog. Your import statements are importing java.awt.Dialog (or something like that). It is not importing org.controlsfx.dialog.Dialog.

jewelsea
  • 150,031
  • 14
  • 366
  • 406
CAG Gonzo
  • 589
  • 1
  • 5
  • 13
  • Thanks, I made the changes and updated the results in my post. It's still showing errors. Don't know why `show()` is striked through. – rocky May 01 '14 at 22:07
  • A strikethrough generally means the method is deprecated. The Javadoc for that method might say why. What errors are you getting? – CAG Gonzo May 01 '14 at 22:08
  • @jewelsea When I do `import org.controlsfx.dialog.Dialog;`, I get an error `java.awt.Dialog is already defined in a single-type import`. However, defining `import org.controlsfx.dialog.Dialogs;` doesn't throws any error. – rocky May 02 '14 at 19:00
0

Don't import java.awt.Dialog; you have the correct imports mentioned. You also appear to have the showException method still defined in another method, specifically in the try block. You cannot declare a method inside of a method.

CAG Gonzo
  • 589
  • 1
  • 5
  • 13
  • I am not importing `java.awt.Dialog; `. I am importing `import org.controlsfx.dialog.Dialog;` and I am wondering why I am getting ` an error `java.awt.Dialog is already defined in a single-type import`. If I can't define `showException()` inside try-catch block, then how should I go about showing a dialog as soon as exception occurs? By the way `showException()` method doesn't throw any errors when I declare it inside the catch block. – rocky May 05 '14 at 17:41
  • Declare it like a standard method in java. Your import error may be because you have a `java.awt.*` import, and so the compiler cannot distinguish the type to use for the dialog declaration. You can fix this by fully qualifying the type of dialog to use, i.e. `org.controlsfx.dialog.Dialog` instead of just `Dialog`. Also, i just caught my double answer and would like to apologize for not editing my first one or providing a comment. – CAG Gonzo May 05 '14 at 22:20