该帮助的版本不再更新,请参见https://www.jmp.com/support/help/zh-cn/15.2 获取最新的版本.


A script can stop itself by executing the Throw() function. If you want to escape from part of a script when it is in an error condition, you can enclose it in a Try() expression.
Try() takes two expression arguments. It starts by evaluating the first expression, and if or when the first expression throws an exception by evaluating Throw, it does the following:
Throw() does not require an argument but has two types of optional arguments. If you include a character-valued expression as an argument, throwing stores that string in a global named exception_msg; this is illustrated in the first example below.
You can use Try() and Throw() to catch an exception that JMP itself throws.
Try( Throw( "Hello." ), Show( exception_msg ) );
dt = Open( "Mydata.jmp" ); // a file that cannot be opened
Summarize( a = by( age ), c = count, meanHt = Mean( Height ) );
Show( a, c, meanHt );
Print( "This script does not work without the data set." );
Throw();
If the Throw() string begins with “!” and is inside a Try() expression, throwing creates an error message about where the exception was caught.
Throw( "!This message has an exclamation point." );
Write( "\!Nexception_msg: ", exception_msg );
Print( "Hello from the catch block (WITH exclamation)." );
Print( "This AFTER message will NOT print due to error." );
You can also use Try() and Throw() to escape from deep inside For loops.
a = [1 2 3, 4 5 ., 7 8 9];
nr = N Row( a );
nc = N Col( a );
For( i = 1, i <= nr, i++,
For( j = 1, j <= nc, j++,
If( Is Missing( za ),
Throw( "Missing a" )
If( Is Missing( zb ),
Throw( "Missing b" )
Show( i, j, exception_msg );
Throw();
You do not have to use Try() to make use of Throw(). In this example, Throw() is not caught by Try() but still stops a script that cannot proceed:
dt = New Table(); // to get an empty data table
If( N Row( dt ) == 0,
Throw( "!Empty Data Table" )