# How to use the built-in InvalidStateException

**URL:** <https://discourse.julialang.org/t/how-to-use-the-built-in-invalidstateexception/82408>\
**Category:** New to Julia\
**Tags:** exception\
**Created:** [June 8, 2022, 7:22am UTC](https://discourse.julialang.org/t/how-to-use-the-built-in-invalidstateexception/82408 "2022-06-08T07:22:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Atiyah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/atiyah/32/46462_2.png) [@Atiyah](https://discourse.julialang.org/u/Atiyah)\
**Post date:** [June 8, 2022, 7:22am UTC](https://discourse.julialang.org/t/how-to-use-the-built-in-invalidstateexception/82408/1 "2022-06-08T07:22:32Z")

</div>

1. What would be a typical use case for employing the built-in InvalidStateException?

2. Can this exception be employed for inconsistent values of different variables during runtime, i.e. invalid states or inconsistencies of different variable? Or is there a better option?

3. Throwing InvalidStateException requires two arguments a message and a symbol. What would be typical values of a symbol?

---

<div class="post-metadata">

**Author:** ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Post date:** [June 9, 2022, 5:31am UTC](https://discourse.julialang.org/t/how-to-use-the-built-in-invalidstateexception/82408/2 "2022-06-09T05:31:19Z")

</div>

> [@Atiyah](#):
>
> InvalidStateException

It is up to you when to throw it, one should match the words in the exception to the kind of error. The arguments are again, situation dependent and are most likely literals.

Here’s an example from the wild

> <https://github.com/julia-vscode/LanguageServer.jl/issues/1009>
>
> I've just tried to run LanguageServer and encountered the following error:
> 
> \`\`…\`julia
> julia\> using LanguageServer
> 
> julia\> using LanguageServer.SymbolServer
> 
> julia\> runserver()
> ERROR: MethodError: no method matching (::LanguageServer.var"#93#95"{LanguageServerInstance})(::String, ::Int64)
> Closest candidates are:
> (::LanguageServer.var"#93#95")(::Any) at ~/.julia/packages/LanguageServer/JrIEf/src/languageserverinstance.jl:185
> Stacktrace:
> \[1\] getstore(ssi::SymbolServerInstance, environment\_path::String, progress\_callback::LanguageServer.var"#93#95"{LanguageServerInstance}, error\_handler::Nothing; download::Bool)
> @ SymbolServer ~/.julia/packages/SymbolServer/GBhfx/src/SymbolServer.jl:47
> \[2\] macro expansion
> @ ~/.julia/packages/LanguageServer/JrIEf/src/languageserverinstance.jl:182 \[inlined\]
> \[3\] (::LanguageServer.var"#92#94"{LanguageServerInstance})()
> @ LanguageServer ./task.jl:423
> \`\`\`
> 
> I'm on Julia 1.7 with LanguageServer 4.1.0. I've already ried to remove compiled/ and packages/ folders from ~/.julia/ but didn't help. Any ideas what's causing this?

Which if we trace back to where it is thrown

> <https://github.com/JuliaLang/julia/blob/742b9abb4dd4621b667ec5bb3434b8b3602f96fd/base/channels.jl#L163-L173>

and here’s the documentation for that call

[https://docs.julialang.org/en/v1/base/parallel/#Base.take!-Tuple{Channel}](https://docs.julialang.org/en/v1/base/parallel/#Base.take!-Tuple%7BChannel%7D)

What seems to be different in Julia is the docs don’t mention that take! might throw and we have no way of annotating that. Meaning one day you might log in to find you didn’t use `try` in your long running code and you can make a sad face.
