<p dir="auto">Coming from Python, I was really surprised to find that Julia has no way to execute code after a <code class="notranslate">try</code> block <em>only</em> if no exception/error was caught. Right now it seems the only way to get around this is something like:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="try
  maybe_raise_exception()
  unrelated_stuff()
  more_unrelated()
catch
  stuff()
end "><pre class="notranslate"><span class="pl-k">try</span>
  <span class="pl-c1">maybe_raise_exception</span>()
  <span class="pl-c1">unrelated_stuff</span>()
  <span class="pl-c1">more_unrelated</span>()
<span class="pl-k">catch</span>
  <span class="pl-c1">stuff</span>()
<span class="pl-k">end</span> </pre></div>
<p dir="auto">Whereas the Python code for this would read:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="try:
  maybe_raise_exception()
except SomeException:
  stuff()
else:
  unrelated_stuff()
  more_unrelated() "><pre class="notranslate"><span class="pl-k">try</span>:
  <span class="pl-en">maybe_raise_exception</span>()
<span class="pl-k">except</span> <span class="pl-v">SomeException</span>:
  <span class="pl-en">stuff</span>()
<span class="pl-k">else</span>:
  <span class="pl-en">unrelated_stuff</span>()
  <span class="pl-en">more_unrelated</span>() </pre></div>
<p dir="auto">It seems like bad practice to put code that we aren't worried about causing exceptions/errors in a <code class="notranslate">try</code> block so I'm interested in hearing what others have to say about this.</p>
<p dir="auto">e: Alternatively you could do:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="try
  maybe_raise_exception()
  noex = true
catch
  stuff()
end
if noex
  unrelated_stuff()
  more_unrelated()
end"><pre class="notranslate"><span class="pl-k">try</span>
  <span class="pl-c1">maybe_raise_exception</span>()
  noex <span class="pl-k">=</span> <span class="pl-c1">true</span>
<span class="pl-k">catch</span>
  <span class="pl-c1">stuff</span>()
<span class="pl-k">end</span>
<span class="pl-k">if</span> noex
  <span class="pl-c1">unrelated_stuff</span>()
  <span class="pl-c1">more_unrelated</span>()
<span class="pl-k">end</span></pre></div>
<p dir="auto">Although I do personally prefer the <code class="notranslate">else</code> syntax.</p>
<blockquote>
<p dir="auto">master (<a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/JuliaLang/julia/commit/70b6afa4328d2c4a0aef4c432c85a30eca83aadb/hovercard" href="https://github.com/JuliaLang/julia/commit/70b6afa4328d2c4a0aef4c432c85a30eca83aadb"><tt>70b6afa</tt></a>):</p>
</blockquote>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; isequal(Tuple{Vararg{Int, N}} where N)
julia&gt; isequal(Tuple{Vararg{Int, N}} where N)
ERROR: TypeError: in new, expected DataType, got Type{Tuple{Vararg{Int64, N}} where N}
Stacktrace:
 [1] Base.Fix2(f::typeof(isequal), x::Type{Tuple{Vararg{Int64}}})
   @ Base ./operators.jl:1059
 [2] isequal(x::Type)
   @ Base ./operators.jl:1074
 [3] top-level scope
   @ none:1"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-c1">isequal</span>(Tuple{Vararg{Int, N}} <span class="pl-k">where</span> N)
julia<span class="pl-k">&gt;</span> <span class="pl-c1">isequal</span>(Tuple{Vararg{Int, N}} <span class="pl-k">where</span> N)
ERROR<span class="pl-k">:</span> TypeError<span class="pl-k">:</span> <span class="pl-k">in</span> new, expected DataType, got Type{Tuple{Vararg{Int64, N}} <span class="pl-k">where</span> N}
Stacktrace<span class="pl-k">:</span>
 [<span class="pl-c1">1</span>] Base<span class="pl-k">.</span><span class="pl-c1">Fix2</span>(f<span class="pl-k">::</span><span class="pl-c1">typeof</span>(isequal), x<span class="pl-k">::</span><span class="pl-c1">Type{Tuple{Vararg{Int64}}}</span>)
   @ Base <span class="pl-k">./</span>operators<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">1059</span>
 [<span class="pl-c1">2</span>] <span class="pl-c1">isequal</span>(x<span class="pl-k">::</span><span class="pl-c1">Type</span>)
   @ Base <span class="pl-k">./</span>operators<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">1074</span>
 [<span class="pl-c1">3</span>] top<span class="pl-k">-</span>level scope
   @ none<span class="pl-k">:</span><span class="pl-c1">1</span></pre></div>
<blockquote>
<p dir="auto">1.6-rc1</p>
</blockquote>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; isequal(Tuple{Vararg{Int, N}} where N)
(::Base.Fix2{typeof(isequal), UnionAll}) (generic function with 1 method)"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-c1">isequal</span>(Tuple{Vararg{Int, N}} <span class="pl-k">where</span> N)
(<span class="pl-k">::</span><span class="pl-c1">Base.Fix2{typeof(isequal), UnionAll}</span>) (generic <span class="pl-k">function</span> with <span class="pl-c1">1</span> method)</pre></div>
<p dir="auto">I confirmed this issue disappears after checking out to <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/JuliaLang/julia/commit/3635f0473dea7c7254d611e3eaa939e0f6dd9484/hovercard" href="https://github.com/JuliaLang/julia/commit/3635f0473dea7c7254d611e3eaa939e0f6dd9484"><tt>3635f04</tt></a>, so I guess this is caused by <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/JuliaLang/julia/commit/8fc52931fca94f4247f2b0e8f69447f8417d70ab/hovercard" href="https://github.com/JuliaLang/julia/commit/8fc52931fca94f4247f2b0e8f69447f8417d70ab"><tt>8fc5293</tt></a> .</p>
<p dir="auto">/cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/vtjnash/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/vtjnash">@vtjnash</a></p>