# Error when file is not found

**URL:** https://discourse.julialang.org/t/error-when-file-is-not-found/106665
**Category:** General Usage
**Tags:** filesystem
**Created:** [November 24, 2023, 7:46am UTC](https://discourse.julialang.org/t/error-when-file-is-not-found/106665 "2023-11-24T07:46:06Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [November 24, 2023, 8:39am UTC](https://discourse.julialang.org/t/error-when-file-is-not-found/106665/2 "2023-11-24T08:39:36Z")

</div>

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](https://discourse.julialang.org/t/a-julia-equivalent-to-rs-stop/36568/13). 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.

---

_[View the full topic](https://discourse.julialang.org/t/error-when-file-is-not-found/106665)._
