cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.
  • See how to access JMP Marketplace - and - find, create & share add-ins to extend your JMP. Watch video.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
awsmagala
Level II

Purposefully Raising Error in JSL

I 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.

 

 

4 REPLIES 4
txnelson
Super User

Re: Purposefully Raising Error in JSL

use the Try() function and then check on the results of it
Jim
Jeff_Perkinson
Community Manager Community Manager

Re: Purposefully Raising Error in JSL

You 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

 

 

-Jeff
pmroz
Super User

Re: Purposefully Raising Error in JSL

I 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());
David_Burnham
Super User (Alumni)

Re: Purposefully Raising Error in JSL

You 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,
	<<OnValidate(
		n = teb << Get;
		show(n);
		If (n<=100,
			isValid = 1;
			tbStatus <<SetText("")
		,
			isValid = 0;
			tbStatus <<SetText("try again!")
		);
		isValid
	),
	BorderBox(Top(20),Bottom(20),Left(20),Right(20),
		VListBox(
			HListBox(
				TextBox("Enter a number less than 100:  "),
				teb = NumberEditBox()
			),
			tbStatus = TextBox("",<<FontColor("red"))
		)
	)
);
show(n)

 

-Dave

Recommended Articles