# Efficient use of test or assert

**URL:** https://discourse.julialang.org/t/efficient-use-of-test-or-assert/75895
**Category:** New to Julia
**Tags:** error-message
**Created:** [February 6, 2022, 9:14am UTC](https://discourse.julialang.org/t/efficient-use-of-test-or-assert/75895 "2022-02-06T09:14:39Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [February 6, 2022, 1:14pm UTC](https://discourse.julialang.org/t/efficient-use-of-test-or-assert/75895/4 "2022-02-06T13:14:59Z")

</div>

For a package-free alternative, `throw(DomainError(...))` also seems to be recommended in [this other thread](https://discourse.julialang.org/t/error-vs-throw-argumenterror/18915).

Example:

```julia
dB(x) = (x > 0) ? 20*log10(x) : throw(DomainError(x, "argument <= 0"))
dB(0.5) # -6.0
dB(-0.5) # ERROR: DomainError with -0.5: argument <= 0

```

---

_[View the full topic](https://discourse.julialang.org/t/efficient-use-of-test-or-assert/75895)._
