Skip to content
This repository has been archived by the owner on May 5, 2020. It is now read-only.

Suggestion: improve the explanation of throw() #29

Open
mark-summerfield opened this issue Mar 6, 2017 · 3 comments
Open

Suggestion: improve the explanation of throw() #29

mark-summerfield opened this issue Mar 6, 2017 · 3 comments

Comments

@mark-summerfield
Copy link

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.)

@yuyichao
Copy link
Contributor

yuyichao commented Mar 6, 2017

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.

@mark-summerfield
Copy link
Author

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.

@yuyichao
Copy link
Contributor

yuyichao commented Mar 6, 2017

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants