# Is there a way to make a Set of Types that all inherit from a supertype?

**URL:** <https://discourse.julialang.org/t/is-there-a-way-to-make-a-set-of-types-that-all-inherit-from-a-supertype/114705>\
**Category:** General Usage\
**Tags:** type\
**Created:** [May 24, 2024, 9:55pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-make-a-set-of-types-that-all-inherit-from-a-supertype/114705 "2024-05-24T21:55:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AwesomeQuest](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/awesomequest/32/38910_2.png) [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Post date:** [May 24, 2024, 9:55pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-make-a-set-of-types-that-all-inherit-from-a-supertype/114705/1 "2024-05-24T21:55:49Z")

</div>

For instance a `Set` that contains `Integer` types like `UInt8`, `Int64`, and so on. Or a `Set` that contains `Exception` types.

First instinct would be

```julia
Set{Type{Exception}}()

```

But that can only store the type `Exception`

You can use

```julia
Set{DataType}()

```

But that just lets any type into the `Set`.

Is there a way to make a `Set` that can only contain children of some superset?

---

<div class="post-metadata">

**Author:** ![aryavorskiy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aryavorskiy/32/43466_2.png) [@aryavorskiy](https://discourse.julialang.org/u/aryavorskiy)\
**Post date:** [May 24, 2024, 10:04pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-make-a-set-of-types-that-all-inherit-from-a-supertype/114705/2 "2024-05-24T22:04:59Z")

</div>

Hi! It seems that what you need is `Set{Type{<:Exception}}`:

```julia-repl
julia> e = Set{Type{<:Exception}}()
Set{Type{<:Exception}}()

julia> push!(e, ErrorException, ArgumentError)
Set{Type{<:Exception}} with 2 elements:
  ErrorException
  ArgumentError

julia> push!(e, Int)
ERROR: MethodError: Cannot `convert` an object of type 
  Type{Int64} to an object of type
  Type{<:Exception}
[...]

```
