Throw exception for not empty array in Julia

Viewed 113

I am trying to throw an exception error when the code takes a non empty array as an input

if isempty(array)
     x = a+b+c
else
throw(DomainError(array, "send empty array"))
end
end

DomainError only works with variables hence i am trying to find something which can work on arrays. Please suggest solution.

Thanks in advance!

1 Answers

What is inside array? It seems to work without problem for me:

julia> array = rand(3)
3-element Array{Float64,1}:
 0.9038850096336988
 0.8609009999595922
 0.30350928970930346

julia> throw(DomainError(array, "This error works just fine!"))
ERROR: DomainError with [0.903885, 0.860901, 0.303509]:
This error works just fine!
Stacktrace:
 [1] top-level scope at REPL[13]:1
Related