Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 36d5684

Browse files
committed
julia: add AbstractMXError as parent type
1 parent 89cb4ad commit 36d5684

File tree

5 files changed

+81
-7
lines changed

5 files changed

+81
-7
lines changed

julia/NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
# v1.6.0
1919

20+
* Add an abstract type `AbstractMXError` as the parent type for all MXNet-related
21+
API errors. (#16235)
22+
2023

2124
# v1.5.0
2225

julia/src/MXNet.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ import Base.Iterators: filter
4343
# exports
4444
###############################################################################
4545

46+
# exceptions.jl
47+
export AbstractMXError,
48+
MXError
49+
4650
# symbolic-node.jl
4751
export SymbolicNode,
4852
Variable,
@@ -135,6 +139,7 @@ export to_graphviz
135139
# includes
136140
###############################################################################
137141

142+
include("exceptions.jl")
138143
include("base.jl")
139144

140145
include("runtime.jl")

julia/src/base.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
"Exception thrown when an error occurred calling MXNet API."
19-
struct MXError <: Exception
20-
msg :: AbstractString
21-
end
22-
23-
Base.show(io::IO, e::MXError) = print(io, e.msg)
24-
2518
################################################################################
2619
# Common types used in MXNet API
2720
################################################################################

julia/src/exceptions.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
19+
"""
20+
Exception thrown when an error occurred calling MXNet API.
21+
"""
22+
abstract type AbstractMXError <: Exception end
23+
24+
"General MXNet API error"
25+
struct MXError <: AbstractMXError
26+
msg::String
27+
28+
MXError(s::AbstractString) = new(string(s))
29+
end
30+
31+
Base.show(io::IO, e::AbstractMXError) = print(io, e.msg)

julia/test/unittest/exceptions.jl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module TestExceptions
19+
20+
using MXNet
21+
using Test
22+
23+
struct MXError′ <: AbstractMXError
24+
msg::String
25+
end
26+
27+
function test_show()
28+
@info "AbstractMXError::Base.show"
29+
30+
io = IOBuffer()
31+
e = MXError′("magic")
32+
print(io, e)
33+
str = String(take!(io))
34+
@test str == "magic"
35+
end
36+
37+
@testset "Exception Test" begin
38+
test_show()
39+
end
40+
41+
42+
end # module TestExceptions

0 commit comments

Comments
 (0)