C# in the NET Framework has a convenient NotImplementedException, that I can throw from code sections that I intend to write later.
Is there a similar assertion in Julia?
Just use error("unimplemented") or throw("unimplemented"). These exceptions are just meant to warn you that something are not implemented, so you might not want to catch or handle them by code. A ErrorException or even ASCIIString is enough.
In Julia, it's quite simple to create your own exception type. Last year, I added the following Exception type to Julia, along with a method to display exactly how I wanted:
const UTF_ERR_SHORT = "invalid UTF-8 sequence starting at index <<1>> (0x<<2>> missing one or more continuation bytes)"
const UTF_ERR_CONT = "invalid UTF-8 sequence starting at index <<1>> (0x<<2>> is not a continuation byte)"
type UnicodeError <: Exception
errmsg::AbstractString ##< A UTF_ERR_ message
errpos::Int32 ##< Position of invalid character
errchr::UInt32 ##< Invalid character
end
show(io::IO, exc::UnicodeError) = print(io, replace(replace(string("UnicodeError: ",exc.errmsg),
"<<1>>",string(exc.errpos)),"<<2>>",hex(exc.errchr)))
Now, to throw a UnicodeError, I can simply do something like:
throw(UnicodeError(UTF_ERR_SHORT, pos, chr))
to get an exception that displays exactly as I want it to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With