Thursday, 17 March 2016

Julia: Throw an exception explicitly


By using throw() function, you can throw an exception explicitly.
julia> function process_info(a)
           if(a<0)
               throw(DomainError())
           elseif(a>100)
               throw(BoundsError())
           else
               println("Processing data")
           end
       end
process_info (generic function with 2 methods)

julia> 

julia> process_info(-10)
ERROR: DomainError:
 in process_info at none:3

julia> process_info(10)
Processing data

julia> process_info(100)
Processing data

julia> process_info(101)
ERROR: BoundsError
 in process_info at none:5



Previous                                                 Next                                                 Home

No comments:

Post a Comment