Skip to main content
Inspiring
May 6, 2013
Question

How to create Exception

  • May 6, 2013
  • 1 reply
  • 529 views

Hi to All !

How I'm can create exception &

......
try{

    .....
    folderAdd(newName);

}

catch(e) {

showError(e);

}


function folderAdd(newName){

myFolder = new Folder(newName);

if (!myFolder.exists) myFolder.create();

    else{
          !!!! in that place I'm whant to create exception !!!!!
    }

}

This topic has been closed for replies.

1 reply

Inspiring
May 6, 2013

Not sure what you are trying to do. You could force an error at that line but there is a chance it would never run. Do you want the exception if the folder already exists? Or do you want the execption if the script is unable to create the folder?

Andy_Bat1Author
Inspiring
May 7, 2013

Sorry...

Yes, I'm want the exception if the folder already exists .

Inspiring
May 7, 2013

You could do something like this

function folderAdd(newName){

    var res;

    var myFolder = new Folder(newName);

    if(myFolder.exists) res = 'Folder already exists';

    if(!myFolder.create()) res = 'Unable to create folder';

    return res;

}

function showError(e){alert(e)};

try{

    var newName = 'test';

    var err = folderAdd(newName);

    if(undefined != err) throw(err);

}

catch(e) {

showError(e);

}