# Is it possible to catch a syntax error within the same file or REPL?

**URL:** https://discourse.julialang.org/t/is-it-possible-to-catch-a-syntax-error-within-the-same-file-or-repl/95701
**Category:** General Usage
**Tags:** exception
**Created:** [March 7, 2023, 10:41pm UTC](https://discourse.julialang.org/t/is-it-possible-to-catch-a-syntax-error-within-the-same-file-or-repl/95701 "2023-03-07T22:41:29Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![lmtzx9h4qqnt](https://avatars.discourse-cdn.com/v4/letter/l/74df32/32.png) [@lmtzx9h4qqnt](https://discourse.julialang.org/u/lmtzx9h4qqnt)
#### Post date: [March 7, 2023, 10:41pm UTC](https://discourse.julialang.org/t/is-it-possible-to-catch-a-syntax-error-within-the-same-file-or-repl/95701/1 "2023-03-07T22:41:29Z")

</div>

Given the two files

`test.jl`:

```julia
f(; kwargs...) = dump(kwargs)

try
	f(a=1, b=2, a=7)
catch ex
	println("Caught exception!")
	dump(ex)
end

```

and `testincl.jl`:

```julia
try
	include("test.jl")
catch ex
	println("Caught exception!")
	dump(ex)
end

```

I get

```julia
$ julia test.jl
ERROR: LoadError: syntax: keyword argument "a" repeated in call to "f" around test.jl:4
Stacktrace:
 [1] top-level scope
   @ test.jl:3
in expression starting at test.jl:3
$ julia testincl.jl
Caught exception!
LoadError
  file: String "test.jl"
  line: Int64 3
  error: ErrorException
    msg: String "syntax: keyword argument \"a\" repeated in call to \"f\" around test.jl:4"

```

I guess it’s somewhat difficult to define how catching syntax errors should work (since after all, the program is not well-formed in that case). It looks like it’s not possible within the same file (or REPL), but maybe there’s some “hidden” way?
