Verbosity aside, (which may also be disputable since errors are supposed to
be rare...), I still do not see the difference even from reading the
constructed examples in the manual: both are examples of functions that are
not defined for negative arguments, but in the first case, the function
throws an exception, in the second it signals an error.
michele

On Fri, Aug 21, 2015 at 6:06 PM, Stefan Karpinski <ste...@karpinski.org>
wrote:

> This is actually an old debate between me and Jeff. The distinction I
> tried to make was that `throw` should be used with catch as a form of
> control flow, while `error` should be used when there's an actual error.
> However, that distinction hasn't stuck, possibly because he never liked it
> and it's common to see `throw(InexactError())` in Base. We could get rid of
> `error` but writing `throw(ErrorException("oops"))` to throw a simple error
> seems pretty unpalatable.
>
> On Fri, Aug 21, 2015 at 11:53 AM, Isaiah Norton <isaiah.nor...@gmail.com>
> wrote:
>
>> Yes.
>>
>> On Fri, Aug 21, 2015 at 11:51 AM, Michele Zaffalon <
>> michele.zaffa...@gmail.com> wrote:
>>
>>> That is my point: error is the same as throw(ErrorException). Should
>>> both co-exist? Is error just a short name for the throw(ErrorException)
>>> version?
>>>
>>> On Fri, Aug 21, 2015 at 5:43 PM, Isaiah Norton <isaiah.nor...@gmail.com>
>>> wrote:
>>>
>>>> `error` is generic, whereas `throw` can raise typed errors, such as
>>>> DomainError, SimdError, UVError, etc. which may have special handling --
>>>> for example, customized `show` methods to print help/suggestions to resolve
>>>> the specific situation.
>>>>
>>>> (see also the examples here:
>>>> http://docs.julialang.org/en/latest/manual/control-flow/?highlight=error#the-try-catch-statement
>>>> )
>>>>
>>>> On Fri, Aug 21, 2015 at 11:32 AM, Michele Zaffalon <
>>>> michele.zaffa...@gmail.com> wrote:
>>>>
>>>>> In what cases should one use error() instead of throw()? The manual
>>>>> <http://docs.julialang.org/en/latest/manual/control-flow/?highlight=error#the-throw-function>
>>>>> is not particular clear about the difference:
>>>>>
>>>>> The error() function is used to produce an ErrorException that
>>>>> interrupts the normal flow of control.
>>>>>
>>>>>
>>>>> Isn't what throw is supposed to do?
>>>>>
>>>>
>>>>
>>>
>>
>

Reply via email to