Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/src/lib/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Package Index

## Internal

```@index
Pages = ["internals.md"]
```
24 changes: 13 additions & 11 deletions src/include/exception.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ d2 = @capture_out quote
)
args = \$(args)

# Defaults
module_name = __module__
error_header = "\$(module_name).\$(exception_name):"

Expand Down Expand Up @@ -97,17 +96,21 @@ macro exception(
context = :()

for (index, arg) in pairs(args)
if arg.head == :(=)
if arg.args[1] == :context
if context_specified
throw(OnlyOneContext())
if typeof(arg) == Expr
if arg.head == :(=)
if arg.args[1] == :context
if context_specified
throw(OnlyOneContext())
else
context = args[index]
args = args[1:end .≠ index]
context_specified = true
end
else
context = args[index]
args = args[1:end .≠ index]
context_specified = true
throw(OnlyOneEquation())
end
else
throw(OnlyOneEquation())
elseif arg.head ≠ :(::) || length(arg.args) ≠ 2
throw(FieldsOnly())
end
end
end
Expand All @@ -121,7 +124,6 @@ macro exception(
)
args = $(args)

# Defaults
module_name = __module__
error_header = "$(module_name).$(exception_name):"

Expand Down
6 changes: 6 additions & 0 deletions src/include/exceptions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ end
"The passed expression(s) for error message (do)es not yield a string."
)

@aux(
FieldsOnly,
"Exception thrown when the passed argument is not a structure field.",
"The passed argument is not a structure field (e.g. `file::String` or `file`)."
)

@aux(
OnlyOneContext,
"Exception thrown when more than one context has been passed.",
Expand Down
5 changes: 5 additions & 0 deletions test/tests/exception.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ end
quote @exception(m, var=v1) end,
)

@test_throws(
Exceptions.Internal.FieldsOnly,
quote @exception(m, 1+1) end,
)

end

# No arguments (macro)
Expand Down