You can load the file in a try
/catch
block, where you can catch the case where the file doesn’t exist. When that happens, you throw a nice error message.
To avoid showing a large stacktrace you can add another try
/catch
block at the root level of your script. You could do just that, without the try
/catch
block described in the previous paragraph, but then it can be harder to know what error you’re dealing with at the root level (when you have a try
close to the source of the error, you can throw for example a custom error type that’s easy to identify at the root level).
To reproduce the R behavior see A Julia equivalent to R's stop()? - #13 by kristoffer.carlsson. It’s not recommended because it doesn’t compose well: maybe your nice error message is enough in your current use case. But if your code ends up being used as a piece in a larger program, then the error message without context might make it more difficult to understand and solve.