Skip to main content
made some changes
Source Link
rcollyer
  • 34.1k
  • 7
  • 94
  • 194

To access the errors, you need to invoke the Front End directly from the kernel. In effect, you end up telling the kernel to tell the FE to tell the kernel to do something, so that the FE can report any errors it finds. The method I use is

ClearAll[getFrontEndErrors]; 
SetAttributes[getFrontEndErrors, HoldAll];HoldAllComplete]; 
getFrontEndErrors[gexpr_]
getFrontEndErrors[expr_] := 
Module[Block[{nb, pinks}, 
    UsingFrontEnd@Internal`WithLocalSettings[UsingFrontEnd[
        nb = CreateDocument[gexprCreateDocument[ExpressionCell[expr, Visible -> False"Output"], 
              Visible -> False, NotebookFileName -> "FEMessages"]; 
        SelectionMove[nb, All, Cell],Cell]; 
        MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]],pinks = MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]]; 
        NotebookClose[nb]
    ]];
    pinks
];

which only returns the FE errors. (Edit: I removed the use of Internal`WithLocalSettings as it has limitations that are counterproductive here.) Note, this creates and destroys a notebook. But, if you are posting the info to an existing notebook, you can bypass those steps and just call

MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]]

which returns an empty list if there are no errors present. (You may have to preced the above code with UsingFrontEnd.)

To access the errors, you need to invoke the Front End directly from the kernel. In effect, you end up telling the kernel to tell the FE to tell the kernel to do something, so that the FE can report any errors it finds. The method I use is

SetAttributes[getFrontEndErrors, HoldAll];
getFrontEndErrors[gexpr_] :=
Module[{nb},
    UsingFrontEnd@Internal`WithLocalSettings[
        nb = CreateDocument[gexpr, Visible -> False, 
                 NotebookFileName -> "FEMessages"];
        SelectionMove[nb, All, Cell],
        MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]],
        NotebookClose[nb]
    ]
];

which only returns the FE errors. Note, this creates and destroys a notebook. But, if you are posting the info to an existing notebook, you can bypass those steps and just call

MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]]

which returns an empty list if there are no errors present. (You may have to preced the above code with UsingFrontEnd.)

To access the errors, you need to invoke the Front End directly from the kernel. In effect, you end up telling the kernel to tell the FE to tell the kernel to do something, so that the FE can report any errors it finds. The method I use is

ClearAll[getFrontEndErrors]; 
SetAttributes[getFrontEndErrors, HoldAllComplete]; 

getFrontEndErrors[expr_] := 
Block[{nb, pinks}, 
    UsingFrontEnd[
        nb = CreateDocument[ExpressionCell[expr, "Output"], 
            Visible -> False, NotebookFileName -> "FEMessages"]; 
        SelectionMove[nb, All, Cell]; 
        pinks = MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]]; 
        NotebookClose[nb]
    ];
    pinks
];

which only returns the FE errors. (Edit: I removed the use of Internal`WithLocalSettings as it has limitations that are counterproductive here.) Note, this creates and destroys a notebook. But, if you are posting the info to an existing notebook, you can bypass those steps and just call

MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]]

which returns an empty list if there are no errors present. (You may have to preced the above code with UsingFrontEnd.)

added 31 characters in body
Source Link
rcollyer
  • 34.1k
  • 7
  • 94
  • 194

To access the errors, you need to invoke the Front End directly from the kernel. In effect, you end up telling the kernel to tell the FE to tell the kernel to do something, so that the FE can report any errors it finds. The method I use is

SetAttributes[getFrontEndErrors, HoldAll];
getFrontEndErrors[gexpr_] :=
Module[{nb, res},
    res = UsingFrontEnd@Internal`WithLocalSettings[
        nb = CreateDocument[gexpr, Visible -> False];False, 
                 NotebookFileName -> "FEMessages"];
        SelectionMove[nb, NextAll, Cell],
        MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]],
        NotebookClose[nb]
    ];
    res]
];

which only returns the FE errors. Note, this creates and destroys a notebook. But, if you are posting the info to an existing notebook, you can bypass those steps and just call

MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]]

which returns an empty list if there are no errors present. (You may have to preced the above code with UsingFrontEnd.)

To access the errors, you need to invoke the Front End directly from the kernel. In effect, you end up telling the kernel to tell the FE to tell the kernel to do something, so that the FE can report any errors it finds. The method I use is

SetAttributes[getFrontEndErrors, HoldAll];
getFrontEndErrors[gexpr_] :=
Module[{nb, res},
    res = UsingFrontEnd@Internal`WithLocalSettings[
        nb = CreateDocument[gexpr, Visible -> False];
        SelectionMove[nb, Next, Cell],
        MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]],
        NotebookClose[nb]
    ];
    res
];

which only returns the FE errors. Note, this creates and destroys a notebook. But, if you are posting the info to an existing notebook, you can bypass those steps and just call

MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]]

which returns an empty list if there are no errors present. (You may have to preced the above code with UsingFrontEnd.)

To access the errors, you need to invoke the Front End directly from the kernel. In effect, you end up telling the kernel to tell the FE to tell the kernel to do something, so that the FE can report any errors it finds. The method I use is

SetAttributes[getFrontEndErrors, HoldAll];
getFrontEndErrors[gexpr_] :=
Module[{nb},
    UsingFrontEnd@Internal`WithLocalSettings[
        nb = CreateDocument[gexpr, Visible -> False, 
                 NotebookFileName -> "FEMessages"];
        SelectionMove[nb, All, Cell],
        MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]],
        NotebookClose[nb]
    ]
];

which only returns the FE errors. Note, this creates and destroys a notebook. But, if you are posting the info to an existing notebook, you can bypass those steps and just call

MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]]

which returns an empty list if there are no errors present. (You may have to preced the above code with UsingFrontEnd.)

added fix that may help with Visible -> False problem
Source Link
rcollyer
  • 34.1k
  • 7
  • 94
  • 194

To access the errors, you need to invoke the Front End directly from the kernel. In effect, you end up telling the kernel to tell the FE to tell the kernel to do something, so that the FE can report any errors it finds. The method I use is

SetAttributes[getFrontEndErrors, HoldAll];
getFrontEndErrors[gexpr_] :=
Module[{nb, res},
    res = UsingFrontEnd@Internal`WithLocalSettings[
        nb = CreateDocument[gexpr, Visible -> False]False];
        SelectionMove[nb, Next, Cell],
        MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]],
        NotebookClose[nb]
    ];
    res
];

which only returns the FE errors. Note, this creates and destroys a notebook. But, if you are posting the info to an existing notebook, you can bypass those steps and just call

MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]]

which returns an empty list if there are no errors present. (You may have to preced the above code with UsingFrontEnd.)

To access the errors, you need to invoke the Front End directly from the kernel. In effect, you end up telling the kernel to tell the FE to tell the kernel to do something, so that the FE can report any errors it finds. The method I use is

SetAttributes[getFrontEndErrors, HoldAll];
getFrontEndErrors[gexpr_] :=
Module[{nb, res},
    res = UsingFrontEnd@Internal`WithLocalSettings[
        nb = CreateDocument[gexpr, Visible -> False],
        MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]],
        NotebookClose[nb]
    ];
    res
];

which only returns the FE errors. Note, this creates and destroys a notebook. But, if you are posting the info to an existing notebook, you can bypass those steps and just call

MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]]

which returns an empty list if there are no errors present. (You may have to preced the above code with UsingFrontEnd.)

To access the errors, you need to invoke the Front End directly from the kernel. In effect, you end up telling the kernel to tell the FE to tell the kernel to do something, so that the FE can report any errors it finds. The method I use is

SetAttributes[getFrontEndErrors, HoldAll];
getFrontEndErrors[gexpr_] :=
Module[{nb, res},
    res = UsingFrontEnd@Internal`WithLocalSettings[
        nb = CreateDocument[gexpr, Visible -> False];
        SelectionMove[nb, Next, Cell],
        MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]],
        NotebookClose[nb]
    ];
    res
];

which only returns the FE errors. Note, this creates and destroys a notebook. But, if you are posting the info to an existing notebook, you can bypass those steps and just call

MathLink`CallFrontEnd[FrontEnd`GetErrorsInSelectionPacket[nb]]

which returns an empty list if there are no errors present. (You may have to preced the above code with UsingFrontEnd.)

Source Link
rcollyer
  • 34.1k
  • 7
  • 94
  • 194
Loading