Dear ImageJ folks:
I am wondering is there a way to throw and handle exceptions in ImageJ? Say, I have a macro script, and it was run within some software, which I believe uses the ImageJ headless option, so I don't know much behind the scene since the ImageJ UI does not show. But the software does log the information using re-directory mechanism, so I can go to the log to see more information. So I am wondering is there anything I can do in the macro to throw an exception whenever one occurs? Something like try-catch statement in C++? I know with ImageJ UI displaying, I can pretty much trace where the error is in the macro script, but the way that ImageJ is launched in the software is not known to me, so it is possible that even if the debugging is done with ImageJ UI showing, I might still run into problems when using the software. I hope there is something I can try. Thanks! Best, Nick |
Hi Nick,
There is not full support for try/catch style handling. But see the IJ.redirectErrorMessages() function: http://imagej.net/developer/macro/functions.html#IJ.redirectErrorMessages Beyond that, you did not say what the software is that is calling ImageJ, so there is little more we can do but speculate. Is the software which is calling ImageJ open source? If so, you could have a look at the source code. Or if it is commercial software, have you contacted the company for support from them? Regards, Curtis On Fri, Feb 14, 2014 at 3:50 PM, nickxtsui <[hidden email]> wrote: > Dear ImageJ folks: > I am wondering is there a way to throw and handle exceptions in ImageJ? > > Say, I have a macro script, and it was run within some software, which I > believe uses the ImageJ headless option, so I don't know much behind the > scene since the ImageJ UI does not show. But the software does log the > information using re-directory mechanism, so I can go to the log to see > more > information. So I am wondering is there anything I can do in the macro to > throw an exception whenever one occurs? Something like try-catch statement > in C++? > > I know with ImageJ UI displaying, I can pretty much trace where the error > is > in the macro script, but the way that ImageJ is launched in the software is > not known to me, so it is possible that even if the debugging is done with > ImageJ UI showing, I might still run into problems when using the software. > > I hope there is something I can try. Thanks! > Best, > Nick > > > > -- > View this message in context: > http://imagej.1557.x6.nabble.com/handling-exceptions-in-ImageJ-macro-tp5006529.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Curtis: Thanks a lot for the prompt response. The IJ.redirectErrorMessages() function does not seem to do the job. Even it is put right after the erroneous code, nothing coded in the log file. Or did I use right?
We contacted the company, yes it is a commercial software, so I am afraid I have no source code. However, the did explain a little how ImageJ is launched from there software. They simply simulate command line like
"D:\fiji\fiji.exe -macro D:\myMacro\sampleMacro.ijm > D:\myLog\log.txt --headless" or something like this I believe. In that case, is there anyway to redirect whatever the exception I can see in UI to the log.txt file whenever something wrong in the macro, or I can only see the exceptions when UI is displayed? Thanks a lot.
Best, Nick On Fri, Feb 14, 2014 at 5:16 PM, Curtis Rueden [via ImageJ] <[hidden email]> wrote:
|
Hi Nick,
> The IJ.redirectErrorMessages() function does not seem to do the job. > Even it is put right after the erroneous code, nothing coded in the > log file. Or did I use right? You have to put IJ.redirectErrorMessages() *before* the error-prone code, not after. But it is rather limited in scope. > nothing coded in the log file Johannes and I did some digging. When headless mode is enabled, you should see all exceptions in the stderr log. This includes both unhandled exceptions and ones handled via the IJ.handleException method. If you do not see any exception in the log, then there was very likely no exception. > "D:\fiji\fiji.exe --headless -macro D:\myMacro\sampleMacro.ijm > D:\myLog\log.txt Note that the invocation above only captures the standard *output* stream, not the standard *error* stream. For that you would need something like: "D:\fiji\fiji.exe --headless -macro D:\myMacro\sampleMacro.ijm > D:\myLog\stdout.txt 2> D:\myLog\stderr.txt Contact the commercial organization responsible for the ImageJ integration for further assistance. Regards, Curtis On Fri, Feb 14, 2014 at 4:35 PM, nickxtsui <[hidden email]> wrote: > Hi Curtis: > Thanks a lot for the prompt response. > > The IJ.redirectErrorMessages() function does not seem to do the job. Even > it is put right after the erroneous code, nothing coded in the log file. Or > did I use right? > > We contacted the company, yes it is a commercial software, so I am afraid I > have no source code. However, the did explain a little how ImageJ is > launched from there software. They simply simulate command line like > > "D:\fiji\fiji.exe -macro D:\myMacro\sampleMacro.ijm > D:\myLog\log.txt > --headless" > > or something like this I believe. In that case, is there anyway to redirect > whatever the exception I can see in UI to the log.txt file whenever > something wrong in the macro, or I can only see the exceptions when UI is > displayed? Thanks a lot. > > Best, > Nick > > > On Fri, Feb 14, 2014 at 5:16 PM, Curtis Rueden [via ImageJ] < > [hidden email]> wrote: > > > Hi Nick, > > > > There is not full support for try/catch style handling. But see the > > IJ.redirectErrorMessages() function: > > > http://imagej.net/developer/macro/functions.html#IJ.redirectErrorMessages > > > > Beyond that, you did not say what the software is that is calling ImageJ, > > so there is little more we can do but speculate. Is the software which is > > calling ImageJ open source? If so, you could have a look at the source > > code. Or if it is commercial software, have you contacted the company for > > support from them? > > > > Regards, > > Curtis > > > > > > On Fri, Feb 14, 2014 at 3:50 PM, nickxtsui <[hidden email]< > http://user/SendEmail.jtp?type=node&node=5006530&i=0>> > > wrote: > > > > > Dear ImageJ folks: > > > I am wondering is there a way to throw and handle exceptions in ImageJ? > > > > > > Say, I have a macro script, and it was run within some software, which > I > > > believe uses the ImageJ headless option, so I don't know much behind > the > > > scene since the ImageJ UI does not show. But the software does log the > > > information using re-directory mechanism, so I can go to the log to see > > > more > > > information. So I am wondering is there anything I can do in the macro > > to > > > throw an exception whenever one occurs? Something like try-catch > > statement > > > in C++? > > > > > > I know with ImageJ UI displaying, I can pretty much trace where the > > error > > > is > > > in the macro script, but the way that ImageJ is launched in the > software > > is > > > not known to me, so it is possible that even if the debugging is done > > with > > > ImageJ UI showing, I might still run into problems when using the > > software. > > > > > > I hope there is something I can try. Thanks! > > > Best, > > > Nick > > > > > > > > > > > > -- > > > View this message in context: > > > > > > http://imagej.1557.x6.nabble.com/handling-exceptions-in-ImageJ-macro-tp5006529.html > > > Sent from the ImageJ mailing list archive at Nabble.com. > > > > > > -- > > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > > > ------------------------------ > > If you reply to this email, your message will be added to the discussion > > below: > > > > > http://imagej.1557.x6.nabble.com/handling-exceptions-in-ImageJ-macro-tp5006529p5006530.html > > To unsubscribe from handling exceptions in ImageJ macro, click here< > > > > . > > NAML< > http://imagej.1557.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml > > > > > > > > > -- > View this message in context: > http://imagej.1557.x6.nabble.com/handling-exceptions-in-ImageJ-macro-tp5006529p5006531.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
I see. Thanks! On Fri, Feb 14, 2014 at 6:09 PM, Curtis Rueden [via ImageJ] <[hidden email]> wrote: Hi Nick, |
Free forum by Nabble | Edit this page |