Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6822769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:42:11+00:00 2026-05-26T21:42:11+00:00

This example routine generates two Throw::nocatch warning messages in the kernel window. Can they

  • 0

This example routine generates two Throw::nocatch warning messages in the kernel window. Can they be handled somehow?

The example consists of this code in a file “test.m” created in C:\Temp:

Needs["JLink`"];
$FrontEndLaunchCommand = "Mathematica.exe";
UseFrontEnd[NotebookWrite[CreateDocument[], "Testing"]];

Then these commands pasted and run at the Windows Command Prompt:

PATH = C:\Program Files\Wolfram Research\Mathematica\8.0\;%PATH%
start MathKernel -noprompt -initfile "C:\Temp\test.m"

enter image description here

Addendum

The reason for using UseFrontEnd as opposed to UsingFrontEnd is that an interactive front end may be required to preserve output and messages from notebooks that are usually run interactively. For example, with C:\Temp\test.m modified like so:

Needs["JLink`"];
$FrontEndLaunchCommand="Mathematica.exe";
UseFrontEnd[
nb = NotebookOpen["C:\\Temp\\run.nb"];
SelectionMove[nb, Next, Cell];
SelectionEvaluate[nb];
];
Pause[10];
CloseFrontEnd[];

and a notebook C:\Temp\run.nb created with a single cell containing:

x1 = 0; While[x1 < 1000000,
 If[Mod[x1, 100000] == 0,
  Print["x1=" <> ToString[x1]]]; x1++];
NotebookSave[EvaluationNotebook[]];
NotebookClose[EvaluationNotebook[]];

this code, launched from a Windows Command Prompt, will run interactively and save its output. This is not possible to achieve using UsingFrontEnd or MathKernel -script “C:\Temp\test.m”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:42:11+00:00Added an answer on May 26, 2026 at 9:42 pm

    During the initialization, the kernel code is in a mode which prevents aborts.

    Throw/Catch are implemented with Abort, therefore they do not work during initialization.

    A simple example that shows the problem is to put this in your test.m file:

    Catch[Throw[test]];
    

    Similarly, functions like TimeConstrained, MemoryConstrained, Break, the Trace family, Abort and those that depend upon it (like certain data paclets) will have problems like this during initialization.

    A possible solution to your problem might be to consider the -script option:

    math.exe -script test.m
    

    Also, note that in version 8 there is a documented function called UsingFrontEnd, which does what UseFrontEnd did, but is auto-configured, so this:

    Needs["JLink`"];
    UsingFrontEnd[NotebookWrite[CreateDocument[], "Testing"]];
    

    should be all you need in your test.m file.

    See also: Mathematica Scripts

    Addendum

    One possible solution to use the -script and UsingFrontEnd is to use the ‘run.m script
    included below. This does require setting up a ‘Test’ kernel in the kernel configuration options (basically a clone of the ‘Local’ kernel settings).

    The script includes two utility functions, NotebookEvaluatingQ and NotebookPauseForEvaluation, which help the script to wait for the client notebook to finish evaluating before saving it. The upside of this approach is that all the evaluation control code is in the ‘run.m’ script, so the client notebook does not need to have a NotebookSave[EvaluationNotebook[]] statement at the end.

    NotebookPauseForEvaluation[nb_] := Module[{},While[NotebookEvaluatingQ[nb],Pause[.25]]]
    
    NotebookEvaluatingQ[nb_]:=Module[{},
    SelectionMove[nb,All,Notebook];
    Or@@Map["Evaluating"/.#&,Developer`CellInformation[nb]]
    ]
    
    UsingFrontEnd[
    nb = NotebookOpen["c:\\users\\arnoudb\\run.nb"];
    SetOptions[nb,Evaluator->"Test"];
    SelectionMove[nb,All,Notebook];
    SelectionEvaluate[nb];
    NotebookPauseForEvaluation[nb];
    NotebookSave[nb];
    ]
    

    I hope this is useful in some way to you. It could use a few more improvements like resetting the notebook’s kernel to its original and closing the notebook after saving it,
    but this code should work for this particular purpose.

    On a side note, I tried one other approach, using this:

    UsingFrontEnd[ NotebookEvaluate[ "c:\\users\\arnoudb\\run.nb", InsertResults->True ] ]
    

    But this is kicking the kernel terminal session into a dialog mode, which seems like a bug
    to me (I’ll check into this and get this reported if this is a valid issue).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following this example, I can list all elements into a pdf file import pyPdf
I have this stored procedure. How can I run this for example with intervals
I have access to some images that can be gathered like this: http://www.example.com/imageGetter.php?a=0001 If
This example is from php.net: <?php function Test() { static $a = 0; echo
This example uses a StringWriter to hold the serialized data, then calling ToString() gives
This example is simplified a bit, but in my ASP.NET web page in my
this example below works when hover event is trigered and when its not, its
This example is taken from w3schools . CREATE TABLE Persons ( P_Id int NOT
Given this example: <img class=a /> <img /> <img class=a /> <img class=a id=active
Consider this example table (assuming SQL Server 2005): create table product_bill_of_materials ( parent_product_id int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.