Skip to content

Commit e09eca2

Browse files
kshyattfredrikekre
authored andcommitted
More doctests and wording fixes for IO stuff (#25068)
1 parent 5a2ef5f commit e09eca2

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

base/io.jl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,24 @@ buffer_writes(x::IO, bufsize=SZ_UNBUFFERED_IO) = x
3333
"""
3434
isopen(object) -> Bool
3535
36-
Determine whether an object - such as a stream, timer, or mmap -- is not yet closed. Once an
37-
object is closed, it will never produce a new event. However, a closed stream may still have
38-
data to read in its buffer, use [`eof`](@ref) to check for the ability to read data.
36+
Determine whether an object - such as a stream, timer, or [`mmap`](@ref Mmap.mmap)
37+
-- is not yet closed. Once an object is closed, it will never produce a new event.
38+
However, since a closed stream may still have data to read in its buffer,
39+
use [`eof`](@ref) to check for the ability to read data.
3940
Use the `FileWatching` package to be notified when a stream might be writable or readable.
41+
42+
# Examples
43+
```jldoctest
44+
julia> io = open("my_file.txt", "w+");
45+
46+
julia> isopen(io)
47+
true
48+
49+
julia> close(io)
50+
51+
julia> isopen(io)
52+
false
53+
```
4054
"""
4155
function isopen end
4256

base/replutil.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,29 @@ end
172172
"""
173173
showerror(io, e)
174174
175-
Show a descriptive representation of an exception object.
175+
Show a descriptive representation of an exception object `e`.
176+
This method is used to display the exception after a call to [`throw`](@ref).
177+
178+
# Examples
179+
```jldoctest
180+
julia> struct MyException <: Exception
181+
msg::AbstractString
182+
end
183+
184+
julia> function Base.showerror(io::IO, err::MyException)
185+
print(io, "MyException: ")
186+
print(io, err.msg)
187+
end
188+
189+
julia> err = MyException("test exception")
190+
MyException("test exception")
191+
192+
julia> sprint(showerror, err)
193+
"MyException: test exception"
194+
195+
julia> throw(MyException("test exception"))
196+
ERROR: MyException: test exception
197+
```
176198
"""
177199
showerror(io::IO, ex) = show(io, ex)
178200

0 commit comments

Comments
 (0)