Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move error.jl docs inline; add example to catch_backtrace() #18961

Closed
wants to merge 2 commits into from

Conversation

xorJane
Copy link
Contributor

@xorJane xorJane commented Oct 15, 2016

I moved docstrings inline for a few functions declared in error.jl and augmented the docs slightly for catch_backtrace(). ref #7283

Thanks in advance and happy Saturday!

catch_backtrace()

Get the backtrace of the current exception, for use within `catch` blocks.
The backtrace is represented as an Array{Ptr{Void}} of addresses, so [`showerror`](:func:`showerror`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code highlight Array{Ptr{Void}}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks!

bt = catch_backtrace()
showerror(STDOUT, y, bt)
end
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the output of calling say f(-1) is repeatable, is it worth doctesting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output seems system dependent. I get

DomainError: in f(::Int64) at ./REPL[49]:2 in eval(::Module, ::Any) at ./boot.jl:238 in eval(::Module, ::Any) at /Users/jane/Applications/julia/usr/lib/julia/sys.dylib:? in eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:66 in macro expansion at ./REPL.jl:97 [inlined] in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at ./event.jl:65

Is there a work-around/way to exclude local paths so I can include a doctest?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think those eval backtrace lines always get filtered out of doctest outputs so don't need to be included (they also might be different if run from repl vs a script)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the doctest without eval backtrace lines!

@kshyatt kshyatt added domain:docs This change adds or pertains to documentation domain:error handling Handling of exceptions by Julia or the user labels Oct 17, 2016
@kshyatt
Copy link
Contributor

kshyatt commented Oct 25, 2016

@tkelman is this good to go?


julia> f(-1)
DomainError:
in f(::Int64) at ./REPL[24]:2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this doctest pass like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I made a mistake. As you suggested earlier, the output from running doctests is different from what you get at the repl.

Additionally, it looks like I need to add a println() statement to get the doctest to pass. For example,

julia> f(x) = try
           sqrt(x)
       catch y
           bt = catch_backtrace()
           showerror(STDOUT, y, bt)
           println()
       end;

julia> f(-1)
DomainError:
 in f(::Int64) at ./none:2
 in eval(::Module, ::Any) at ./boot.jl:236
...

and

julia> f(x) = try
           sqrt(x)
       catch y
           bt = catch_backtrace()
           showerror(STDOUT, y, bt)
       end;

julia> f(-1); println()
DomainError:
 in f(::Int64) at ./none:2
 in eval(::Module, ::Any) at ./boot.jl:236
...

pass, but they fail when I remove println(). Do you think either of the above is an adequate solution?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's strange. what does running the doctests say for "got" without the println ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buffering issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tkelman Excluding the system dependent info from "got", I see

File "stdlib/base.rst", line 1234, in default
Failed example:
    f(-1)
Expected:
    DomainError:
     in f(::Int64) at ./none:2
     in eval(::Module, ::Any) at ./boot.jl:236
    ...
Got:
    DomainError:
     in f(::Int64) at ./none:2
     in eval(::Module, ::Any) at ./boot.jl:236

I haven't been able to identify additional or missing whitespace as the problem.

@yuyichao Sorry, what do you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's

Excluding the system dependent info from "got", I see

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to output that included local paths. The full output is:

Got:
    DomainError:
     in f(::Int64) at ./none:2
     in eval(::Module, ::Any) at ./boot.jl:236
     in eval(::Module, ::Any) at /Users/jane/Applications/julia/usr/lib/julia/sys.dylib:?
     in eval_user_input(::Any, ::Bool) at ./client.jl:123
     in eval_user_input(::Any, ::Bool) at /Users/jane/Applications/julia/usr/lib/julia/sys.dylib:?
     in eval(::Module, ::Any) at ./boot.jl:236
     in eval(::Module, ::Any) at /Users/jane/Applications/julia/usr/lib/julia/sys.dylib:?
     in eval_user_input(::Any, ::Bool) at ./client.jl:123
     in eval_user_input(::Any, ::Bool) at /Users/jane/Applications/julia/usr/lib/julia/sys.dylib:?
     in _start() at ./client.jl:372
     in _start() at /Users/jane/Applications/julia/usr/lib/julia/sys.dylib:?**

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be included since it at least means what tony said won't work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the doctest system specifically removes those, but I'm not sure where that happens

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be included since it at least means what tony said won't work.

This doctest fails even when I include the full output listed for "got".

After formatting this doctest several different ways, the only solutions I found involved adding calls to println(). I suspect there may be a bug in the way the doctest system is parsing this code block, but I did not find anything suspicious after going through what I could find of the documentation code. If there aren't other suggestions for things I might try, then I think I will move on to other fronts. Please let me know if you'd like me to convert this doctest to a regular code block or make some other modification. Thanks! :)

@fredrikekre
Copy link
Member

#23272

@tkelman
Copy link
Contributor

tkelman commented Aug 29, 2017

Though the catch_backtrace docstring doesn't have a doctest example yet, but that may be tricky to get to pass. It could be added as julia-repl maybe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:docs This change adds or pertains to documentation domain:error handling Handling of exceptions by Julia or the user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants