10
$\begingroup$

When I open mathematica, there will pop-up some messages

enter image description here

where

<< package` 

is in the following file

FindFile["init.m"]

(*
    C:\Users\HyperGroups\AppData\Roaming\Mathematica\Kernel\init.m
*)

package content in the package file:

BeginPackage["Test1`"]

Test1::usage = "";

Begin["`Private`"];

Nearest[{1, 2, 3, 5, 8, 5}, 5]

End[]

EndPackage[]

I've tried * Mathematica * 10.1@Windows and 10.0[without this problem]

Seems the problem is related with some special functions, like Nearest

$\endgroup$
3
  • $\begingroup$ Problem confirmed in 10.1.0 under Windows 7 x64. $\endgroup$
    – Mr.Wizard
    Commented May 27, 2015 at 14:45
  • 1
    $\begingroup$ should this be tagged as a bug? $\endgroup$
    – P. Fonseca
    Commented May 28, 2015 at 5:38
  • 2
    $\begingroup$ Certainly it is one, but a fix would be (very) non-trivial. I tend to view it as more of a limitation. $\endgroup$
    – ilian
    Commented May 28, 2015 at 14:18

1 Answer 1

17
$\begingroup$

Update

This has been fixed in a general way as of version 11.2.0. For more details, see this answer.


This is a known issue. It is not about package loading (or Nearest) but about Catch/Throw not working correctly when used during kernel initialization. For example, just putting the following in init.m

Catch[Throw[1]]

will result in similar behavior. See also Arnoud Buzing's post here.

The workaround I've been using is to run any init code depending on Catch/Throw as a scheduled task, e.g.

task := Get["package`"];
RunScheduledTask[task, {1}]
$\endgroup$
2
  • 1
    $\begingroup$ I must be missing something... nowhere in the OP's code is there a call to Catch or Throw. Should I understand that there are calls to these functions inside Nearest? $\endgroup$
    – QuantumDot
    Commented May 25, 2016 at 9:01
  • 1
    $\begingroup$ @QuantumDot Yes, see e.g. TracePrint[Nearest[{1, 2, 4, 8, 16, 32}, 20], _Catch, TraceInternal -> True] $\endgroup$
    – ilian
    Commented May 25, 2016 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.