Purposefully Raising Error in JSLI have been searching the forum and scripting index for a way to do this but have not found anything to accomplish what I am trying to do. I am looking for something that has similar functionality to Python's "Raise" function. Or essentially the same functionality as the Try Throw statements but without a JSL exception being raised.
For example I am writing a function that requires the user to enter a date in the form of a string. In order to prevent errors I want to check the input before using it in the function.
Example Function = Function({start_date,end_date},
chk1 = Is String(start_date);
If(chk1 == 0, //Raise some error here);
);I think I could accomplish what I want with a Show("Error message") and Break() sequence but I am wondering if there is any native JSL methods to accomplish this task.
Re: Purposefully Raising Error in JSLYou can use Throw to throw an error. In the context of capturing user input errors you can use a modal window with an OnValidate message:
NewWindow("Demo", <<MODAL></MODAL>
Re: Purposefully Raising Error in JSLI use a combination of a modal window to provide an error message for the user, and throw to terminate execution.
Example Date Check = Function({start_date,end_date},
chk1 = Is String(start_date);
If (!chk1 == 0,
emsg = "Invalid start date [" || char(start_date) || "]";
ew = new window("Invalid date", << modal(),
text box(emsg),
);
throw(emsg);
);
chk2 = Is String(end_date);
If (!chk2 == 0,
emsg = "Invalid end date [" || char(end_date) || "]";
ew = new window("Invalid date", << modal(),
text box(emsg),
);
throw(emsg);
);
);
example date check(today(), today());
example date check("31-Feb-2018", today());Re: Purposefully Raising Error in JSLYou can use Throw() without a try. I think it's similar to Raise() in Python.
//:*/
show("Here");
throw("This didn't work");
show("Here 2");
/*:
"Here";
This didn't work
Re: Purposefully Raising Error in JSLuse the Try() function and then check on the results of it