How do you get the run-time exception programmatically?

Hi All,

So, I am having trouble getting the run-time error off of IntelliJ using Java. Part of the feature of my plugin is being  able to retrieve the run-time error of the user's Java program. An example of a run-time error I want to get from IntelliJ is the java.lang.NullPointerException and its stack-trace.

I know that you can do the following to get the compilation error message. Is there a similar way I can get  the run-time errors from IntelliJ? Thanks for the help :) 

final MessageBusConnection conn = myProject.getMessageBus().connect();
conn.subscribe(CompilerTopics.COMPILATION_STATUS, new CompilationStatusListener() {
// code to handle when compilation is finished etc
});
7 comments
Comment actions Permalink

Hi,

do you mean you want to get notified when inspections detect some error/warning? You can try with com.intellij.problems.WolfTheProblemSolver.ProblemListener but it would work for errors only. There is no API for custom highlighting as far as I know

Anna

0
Comment actions Permalink

Hi Anna,

Sort of. Below is a screenshot of what I want to capture: 

So the red error message (minus the Hello world) is what I want to capture in my plugin. Can WolfTheProblemSolver.ProblemListener help me get those messages from the thread?

Thanks,

Dan 

0
Comment actions Permalink

Do you mean that you have an exception in the console and want to detect null pointer exception there?

0
Comment actions Permalink

Yes. The null-pointer exception was just an example. In general, I want to be able to detect exceptions in the console whenever there exist one. It doesn't have to be null pointer exception.

 

0
Comment actions Permalink

Then my first suggestion is absolutely not applicable, sorry. Take a look at com.intellij.execution.filters.ConsoleFilterProvider and it's subclass com.intellij.execution.filters.ConsoleDependentFilterProvider. You'll be able to provide your filter which would be fed with lines from console.

0
Comment actions Permalink

oh I see. Let me give it a try and I will let you know if it works or not. Thanks! 

0
Comment actions Permalink

Hi Anna,

So I tried looking in those classes, and I didn't see the code I needed to achieve what I want. I was looking through the IntelliJ Github repo. Wouldn't it make sense to use al listener to listen whenever the console outputs an error message? The two classes you gave me didn't really show how can I listen for console events.  Can you please help me?

Thanks,

Dan 

0

Please sign in to leave a comment.