# The Julia Debugging Cheat Sheet

**URL:** https://discourse.julialang.org/t/the-julia-debugging-cheat-sheet/69751
**Category:** New to Julia
**Tags:** debugging, cheatsheets
**Created:** [October 14, 2021, 12:32pm UTC](https://discourse.julialang.org/t/the-julia-debugging-cheat-sheet/69751 "2021-10-14T12:32:30Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)
#### Post date: [October 14, 2021, 1:54pm UTC](https://discourse.julialang.org/t/the-julia-debugging-cheat-sheet/69751/2 "2021-10-14T13:54:00Z")

</div>

Not a bad idea, but I don’t think the chart would look much different for Julia. Most of the standard debugging practices under “no” still apply. Some of the error names are different. The list of possible errors are described in the manual [here](https://docs.julialang.org/en/v1/base/base/#Errors).

# Common Errors

The most common error in Julia is probably `MethodError` which means you did not pass values of the correct type or in the correct order to a function. The fix is to look at the docstring for the function with `?function_name` to see what the function expects.

Another error you might see is `UndefVarError` which might mean you didn’t load the package with `using PackageName` yet.

# Common Expectations

I am trying to think of Julia specific “gotchas”, but not coming up with many inside of `Base` Julia.

## First

Probably the biggest is that loops do not know about global variables unless you use the `global` keyword, so the following will not work when run from a file unless you uncomment the third line.

```julia-auto
j=1
while j<10
    # global j
    println(j)
    j+=1
end

```

However, Julia lets you know about this now with a warning.

```julia-auto
┌ Warning: Assignment to `j` in soft scope is ambiguous because a global variable by the same name exists: `j` will be treated as a new local. Disambiguate by using `local j` to suppress this warning or `global j` to assign to the existing global variable.
ERROR: LoadError: UndefVarError: j not defined

```

## Second

Parentheses are not allowed for indexing, but again Julia’s error message lets you know.

```julia-auto
julia> v(2)
ERROR: MethodError: objects of type Vector{Int64} are not callable
Use square brackets [] for indexing an Array.

```

## Third

Lastly, assigning an array to a variable does not copy it unless you ask.

```julia-auto
julia> A=[1,2,3]
3-element Vector{Int64}:
 1
 2
 3

julia> B=A
3-element Vector{Int64}:
 1
 2
 3

julia> C=copy(A)
3-element Vector{Int64}:
 1
 2
 3

julia> A[1]=50
50

julia> println(A,B,C)
[50, 2, 3][50, 2, 3][1, 2, 3]

```

## Others

Some others are in [this post](https://discourse.julialang.org/t/what-are-common-mistakes-in-julia-that-beginners-should-aware-of/51874), but they are somewhat more advanced.

---

_[View the full topic](https://discourse.julialang.org/t/the-julia-debugging-cheat-sheet/69751)._
