-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return null instead of exception if no webcam detected #29
Comments
Agree, but I'm thinking if returning I can change the code as you suggested, but this will cause new release to be incompatible with previous ones. E.g. such fragment will not compile and users will have to modify code: class Test {
private static Webcam webcam = Webcam.getDefault();
} To: class Test {
private static Webcam webcam = null;
static {
try {
webcam = Webcam.getDefault();
} catch (WebcamNotFoundException e) {
// do something
}
}
} In case of final fields this will be more complicated, so either final modifier will have to be removed, or special static initializer method would have to be prepared. Let's assume the second one: class Test {
private static final Webcam WEBCAM = getWebcam();
private static Webcam getWebcam() {
try {
return Webcam.getDefault();
} catch (WebcamNotFoundException e) {
return null;
}
}
} Above will still result in setting |
ok,cause the line 373 in Webcam class ,i can not know there is an exception ,i will catch it now
to this
|
This is doable, of course and I will add such throws closure, but please note that it will not affect end-users code since From the other side, if I change In terms of this issue I would do the following:
|
@sarxos yes,return null is enough~I agree.I talk about this cause i forgot to catch the WebcamException |
Ok then. I will include this change in upcoming 0.3.8. |
yeap,thank you |
@sarxos wow,thanks a lot. |
No problem :) Hope this will help to resolve your project issues :D |
hello,i think that you should not raise an exception that the user can't know from the method sign,and may be an exception witch can be catched such like "NoWebCamException" or just return null when we get webcam.
thanks,the current implment cause an exception uncatched when there is no webcam connected to the PC,
The text was updated successfully, but these errors were encountered: