# Getting nothing when a key is not present in a Dict

**URL:** https://discourse.julialang.org/t/getting-nothing-when-a-key-is-not-present-in-a-dict/65376
**Category:** New to Julia
**Tags:** dictionary
**Created:** [July 27, 2021, 2:19pm UTC](https://discourse.julialang.org/t/getting-nothing-when-a-key-is-not-present-in-a-dict/65376 "2021-07-27T14:19:34Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![orome](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orome/32/26965_2.png) [@orome](https://discourse.julialang.org/u/orome)
#### Post date: [July 27, 2021, 2:19pm UTC](https://discourse.julialang.org/t/getting-nothing-when-a-key-is-not-present-in-a-dict/65376/1 "2021-07-27T14:19:35Z")

</div>

Other than just `try`ing, is there an idiom for returning `nothing` rather than throwing a `KeyError` when a key is missing from a `Dict`.

I’m imagining something like

```julia
something(x[y], something_when_y_is_absent)

```

along the lines of Haskell’s

```haskell
 fromMaybe something_when_y_is_absent (M.lookup y x)

```

---

<div class="post-metadata">

### Author: ![dilumaluthge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dilumaluthge/32/29283_2.png) [@dilumaluthge](https://discourse.julialang.org/u/dilumaluthge)
#### Post date: [July 27, 2021, 2:23pm UTC](https://discourse.julialang.org/t/getting-nothing-when-a-key-is-not-present-in-a-dict/65376/2 "2021-07-27T14:23:37Z")

</div>

```julia
get(x, y, nothing)

```
