JuliaDoc icon indicating copy to clipboard operation
JuliaDoc copied to clipboard

Suggestion: improve the explanation of throw()

Open mark-summerfield opened this issue 8 years ago • 3 comments

In http://docs.julialang.org/en/latest/manual/control-flow.html the section just before the one explaining throw() shows how to create a custom exception with no arguments, which is fine.

Then in the throw() section, it explains how to create a custom error using a Symbol -- but it doesn't show how to throw this (and it isn't obvious to me and I tried unsuccessfully in the REPL).

Also, it should give an example showing how to create (and throw!) an exception that takes a string (or give the reason why this isn't good practice -- although a string-accepting exception is shown in the sidebar).

There should also be a comment on how custom exceptions should be named: the first example is for MyCustomException, but I'm guessing that the naming convention is now the same as Python's and maybe that example should be MyCustomError? Whatever the case is, it should be explained. (And if both -Exception and -Error are legitimate, again explain why and when to use which.)

mark-summerfield avatar Mar 06 '17 09:03 mark-summerfield

but it doesn't show how to throw

It does

julia> throw(UndefVarError(:x))
ERROR: UndefVarError: x not defined

how to create (and throw!) an exception that takes a string

And it does too,

throw(DimensionMismatch("A has first dimension...")).

We are showing the use of throw here with some basic example of the syntax. Since exceptions are nothing different from normal objects and custom ones are no different from builtin once, we don't need to repeat all that here though a link could be good. A link to style guideline (and possibly expand it for exception naming) can also be good.

yuyichao avatar Mar 06 '17 12:03 yuyichao

The first example doesn't help because at this point in the manual :symbol has not been explained so it doesn't make much sense.

The second example shows how to throw with a string -- but doesn't show how to create an exception that accepts a string.

mark-summerfield avatar Mar 06 '17 13:03 mark-summerfield

but doesn't show how to create an exception that accepts a string.

And that's why I mentioned:

though a link (to creating custom objects) could be good

yuyichao avatar Mar 06 '17 13:03 yuyichao