# Best way to write nested try/catch blocks

**URL:** <https://discourse.julialang.org/t/best-way-to-write-nested-try-catch-blocks/30478>\
**Category:** New to Julia\
**Created:** [October 30, 2019, 4:20am UTC](https://discourse.julialang.org/t/best-way-to-write-nested-try-catch-blocks/30478 "2019-10-30T04:20:31Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 30, 2019, 6:56am UTC](https://discourse.julialang.org/t/best-way-to-write-nested-try-catch-blocks/30478/2 "2019-10-30T06:56:07Z")

</div>

Organize your code differently. Traits would help in general, but may require more investment, `hasmethod` would be the quick & dirty way.

FWIW, if this is related to

> [@What's a good way to get some value (doesn't matter what the value is) of a type \`T\` \`where T\`](https://discourse.julialang.org/t/whats-a-good-way-to-get-some-value-doesnt-matter-what-the-value-is-of-a-type-t-where-t/30474/):
>
> I am writing some program that requires a value from a type T but it doesn’t matter what this type is. Is there a generic way to get some value of type T for whatever T? Happy to accept T for isbits.

then just use one of the solutions suggested there; if you are OK with random values then it makes little sense to attempt to get a zero first — pretty much the same types have `rand` and `zero` defined.

---

_[View the full topic](https://discourse.julialang.org/t/best-way-to-write-nested-try-catch-blocks/30478)._
