10

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

HyperGroups
  • 8,619
  • 1
  • 26
  • 63

1 Answers1

17

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}]
ilian
  • 25,474
  • 4
  • 117
  • 186
  • 1
    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? – QuantumDot May 25 '16 at 09:01
  • 1
    @QuantumDot Yes, see e.g. TracePrint[Nearest[{1, 2, 4, 8, 16, 32}, 20], _Catch, TraceInternal -> True] – ilian May 25 '16 at 15:19