Use function body rescue where possible

This commit is contained in:
Marcel Otto 2018-05-16 01:59:46 +02:00
parent fc4a86483d
commit b4c3dc8d98
3 changed files with 20 additions and 26 deletions

View file

@ -97,12 +97,10 @@ defmodule RDF.IRI do
def absolute?(%URI{scheme: nil}), do: false def absolute?(%URI{scheme: nil}), do: false
def absolute?(%URI{scheme: _}), do: true def absolute?(%URI{scheme: _}), do: true
def absolute?(qname) when is_atom(qname) and not qname in [nil, true, false] do def absolute?(qname) when is_atom(qname) and not qname in [nil, true, false] do
try do
qname |> Namespace.resolve_term |> absolute?() qname |> Namespace.resolve_term |> absolute?()
rescue rescue
_ -> false _ -> false
end end
end
def absolute?(_), do: false def absolute?(_), do: false

View file

@ -55,14 +55,12 @@ defmodule RDF.Serialization do
def format(name) def format(name)
def format(name) when is_binary(name) do def format(name) when is_binary(name) do
try do
name name
|> String.to_existing_atom |> String.to_existing_atom
|> format() |> format()
rescue rescue
ArgumentError -> nil ArgumentError -> nil
end end
end
def format(name) do def format(name) do
format_where(fn format -> format.name == name end) format_where(fn format -> format.name == name end)

View file

@ -46,7 +46,6 @@ defmodule RDF.Turtle.Decoder do
def parse(tokens), do: tokens |> :turtle_parser.parse def parse(tokens), do: tokens |> :turtle_parser.parse
defp build_graph(ast, base) do defp build_graph(ast, base) do
try do
{graph, _} = {graph, _} =
Enum.reduce ast, {RDF.Graph.new, %State{base_iri: base}}, fn Enum.reduce ast, {RDF.Graph.new, %State{base_iri: base}}, fn
{:triples, triples_ast}, {graph, state} -> {:triples, triples_ast}, {graph, state} ->
@ -62,7 +61,6 @@ defmodule RDF.Turtle.Decoder do
rescue rescue
error -> {:error, Exception.message(error)} error -> {:error, Exception.message(error)}
end end
end
defp directive({:prefix, {:prefix_ns, _, ns}, iri}, state) do defp directive({:prefix, {:prefix_ns, _, ns}, iri}, state) do
if IRI.absolute?(iri) do if IRI.absolute?(iri) do