/
error.cr
40 lines (32 loc) · 889 Bytes
/
error.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class IO
class Error < Exception
include SystemError
getter target : String?
protected def self.build_message(message, *, target : File) : String
build_message(message, target: target.path)
end
protected def self.build_message(message, *, target : Nil) : String
message
end
protected def self.build_message(message, *, target) : String
"#{message} (#{target})"
end
def initialize(message : String? = nil, cause : Exception? = nil, *, target = nil)
@target = target.try(&.to_s)
super message, cause
end
end
# Raised when an `IO` operation times out.
#
# ```
# STDIN.read_timeout = 1
# STDIN.gets # raises IO::TimeoutError (after 1 second)
# ```
class TimeoutError < Error
end
class EOFError < Error
def initialize(message = "End of file reached")
super(message)
end
end
end