Re: catching exceptions

Posted by Piotr Wendykier on
URL: http://imagej.273.s1.nabble.com/catching-exceptions-tp3690914p3690915.html

Dear Robert,

This is what I do in my plugins:

Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
    public void uncaughtException(Thread t, Throwable e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw, true);
        e.printStackTrace(pw);
        pw.flush();
        sw.flush();
        IJ.log(sw.toString());
    }
});

Piotr


On Tue, Oct 6, 2009 at 8:37 PM, Robert Dougherty <[hidden email]> wrote:

> Dear Community,
>
> Is there a way I can get a plugin manage, or at least report, exceptions
> like
>
> Exception in thread "Thread-12" java.lang.OutOfMemoryError: Java heap space
>        at Beamformer.<init>(Beamformer.java:234)
>        at
> Beamform_Interactive$BeamformInteractive.beamform(Beamform_Interactive.java:2163)
>        at
> Beamform_Interactive$BeamformInteractive.actuallyBeamform(Beamform_Interactive.java:1780)
>        at
> Beamform_Interactive$BeamformInteractive$2.construct(Beamform_Interactive.java:4139)
>        at SwingWorker$2.run(SwingWorker.java:106)
>        at java.lang.Thread.run(Thread.java:637)
>
> At the moment, the plugin just hangs.  If ImageJ was run from a Terminal
> window in OS-X, then the exception is shown there.  Otherwise, the user has
> no clue what is wrong.  I don't think I want users to have to run Terminal.
>  It seems as thought this issue has been treated before, but I have not been
> able to find the discussion.
>
> Bob
>
>
> Robert Dougherty, Ph.D.
> President, OptiNav, Inc.
> 4176 148th Ave. NE
> Redmond, WA 98052
> Tel. (425)891-4883
> FAX (425)467-1119
> www.optinav.com
> [hidden email]
>