# Should asking for diagonals outside of a matrix throw an error?

**URL:** <https://discourse.julialang.org/t/should-asking-for-diagonals-outside-of-a-matrix-throw-an-error/139840>\
**Category:** New to Julia\
**Tags:** linearalgebra\
**Created:** [October 5, 2026, 4:48pm UTC](https://discourse.julialang.org/t/should-asking-for-diagonals-outside-of-a-matrix-throw-an-error/139840 "2026-10-05T16:48:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahmah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mahmah/32/214326_2.png) [@mahmah](https://discourse.julialang.org/u/mahmah)\
**Post date:** [October 5, 2026, 4:48pm UTC](https://discourse.julialang.org/t/should-asking-for-diagonals-outside-of-a-matrix-throw-an-error/139840/1 "2026-10-05T16:48:14Z")

</div>

Shouldn’t this throw an error instead?

```julia
julia> diag(randn(5,5),5)
Float64[]

```

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [October 6, 2026, 5:25am UTC](https://discourse.julialang.org/t/should-asking-for-diagonals-outside-of-a-matrix-throw-an-error/139840/2 "2026-10-06T05:25:31Z")

</div>

It used to, but was removed by v0.7 for needless obstructions: [Remove checks in tril, triu, and diag by andreasnoack · Pull Request #28480 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/28480). FWIW, an empty vector/matrix is an unspecified convention also found in MATLAB and NumPy.
