GNOME Bugzilla – Bug 702832
No warning for methods declaring throws that do not throw
Last modified: 2018-05-22 14:50:46 UTC
Currently, if a method is declared as throwing an error, and a caller doesn't catch it, there's a warning. However, if a method is declared as throwing an error, and never does throw an error, there's no warning. For larger code bases, gradual changes in error handling can be hard to keep track of, and it would be nice to know if something should be throwing an error, but is not. STEPS TO REPRODUCE 1. Compile the following code: public errordomain SomeError { FISH; } public static void go_fish () throws SomeError { } public static void main () { go_fish (); } ACTUAL RESULTS: No warning that go_fish () doesn't actually throw an error. EXPECTED RESULTS: A warning if go_fish never throws an error (and does not call a method that would, either).
Good idea, patches accepted.
Given that the declaration changes both API and ABI there should be an easy way to suppress warnings. A library which removed the possibility of throwing error in method might still want to declare it to maintain the backward compatibility.
In addition to what Maciej wrote, it's also possible that you write a method that might throw an error in a future version and you already specify 'throws' to avoid breaking the interface later on. For these reasons, there should be no such warning by default. We should only warn if something is wrong, at least by default.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/387.