PixInsight Forum (historical)
Software Development => PCL and PJSR Development => Topic started by: bitli on 2015 February 01 13:28:49
-
I try to reuse some code of BPP. I see the following sequence:
var view = window.mainView;
view.beginProcess( UndoFlag_NoSwapFile );
if ( !f.readImage( view.image ) )
throw new Error( "Unable to read file: " + filePath );
window.keywords = f.keywords;
view.endProcess();
Should the view.endProcess() not be in a finally close so it is processed even in case of error ? I guess it is not too important as the script likely exits, but is there a risk to keep lock memory in case of error?
-- bitli
-
When a script terminates, View.endProcess() is invoked automatically for all View objects that require it. So it is actually much better to let the runtime decide how and when to call View.endProcess() upon a script termination caused by an uncatched exception.
However, View.endProcess() should be called by a script if it handles an exception in a situation like:
try
{
view.beginProcess();
processTheViewHere();
view.endProcess();
}
catch ( x )
{
view.endProcess();
handleTheExceptionHere();
}
or even:
let beingProcessed = null;
try
{
doSomethingThatCanThrowExceptions();
view.beginProcess();
beingProcessed = view;
processTheViewHere();
view.endProcess();
beingProcessed = null;
doSomethingElseThatCanThrowExceptions();
}
catch ( x )
{
if ( beingProcessed )
{
beingProcessed.endProcess();
beingProcessed = null;
}
handleTheExceptionHere();
}