-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create PROJError and raise it in custom error handler
This handler, `log_func`, is registered in `__init__`. It simply throws when the level is at error, and ignores otherwise. Based on pyproj4/pyproj#215.
- Loading branch information
Showing
4 changed files
with
63 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"Exception type based on PROJ error handling" | ||
struct PROJError <: Exception | ||
msg::String | ||
# reset PROJ's error stack on construction | ||
function PROJError(msg) | ||
proj_errno_reset(C_NULL) | ||
new(msg) | ||
end | ||
end | ||
|
||
function Base.showerror(io::IO, err::PROJError) | ||
err = string("PROJError: ", err.msg) | ||
println(io, err) | ||
end | ||
|
||
"Custom error handler, automatically set with `proj_log_func`" | ||
function log_func(user_data::Ptr{Cvoid}, level::Cint, msg::Cstring) | ||
if level == PJ_LOG_ERROR | ||
throw(PROJError(unsafe_string(msg))) | ||
end | ||
return C_NULL | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters