vbsteven04/02/2023, 3:33 PM
to make the the error explicit in the signature, or I can add a
annotation and just throw the exception. Currently I'm favoring the
approach but it has some issues (like the Exception type not being generic). Any opinions on this?
hfhbd04/02/2023, 3:40 PM
vbsteven04/03/2023, 5:41 AM
is that a lot of these methods can frequently "throw" and aside from the annotation on the signature there is no other indication that it can. AFAIK Intellij does not warn when calling a
method that does not handle the exception. Given the tendency for many developers to not read the docs I'm afraid many of these will be missed leading to frequent runtime crashes (not ideal in a GUI library). I put "throw" between quotes because the methods I'm talking about are generated bindings from C code, which use an error pointer argument that gets populated when the C function returned early with an error.
. I put
in there for demonstration purposes. If the
, then it is easy to forget to handle the case where the file does not exist, the file is a directory, or the operation was cancelled (if a cancellable was provided and later used asynchronously)
. The benefit is that the user will be forced to do something with the failure case. My main issue with this solution is that
while I already know it cannot be anything else than
or one of its subclasses.
which narrows down the exception type, but it feels dirty.
hfhbd04/03/2023, 7:43 AM
isn't a common practice. The mapped Java File APIs are similar:
This could also fail with IOException, but there is no hint/language design to explicitly catch the exception. But Kotlin's design is also pragmatic. If it does work for you, use your API design, in this case, I would use your own
class to provide more information.
vbsteven04/03/2023, 8:01 AM
Soren Roth04/04/2023, 6:03 AM
variety of functions which catch all exceptions and return null.
vbsteven04/04/2023, 8:06 AM
approach looks interesting (which is the current implementation) is that it provides some flexibility to the library user. The
class provides some utilities like
type that encapsulates the GError details more clearly using the type system.