开发者

Is this legit to keep a default value and avoid exception?

    private int getScreenWidth(){
        int width;
        try{
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            width =开发者_StackOverflow中文版 screenSize.width >= 1024 ? screenSize.width : 1024;
        }catch(HeadlessException e){
            logger.write("couldnt get screen width" + e);
            width = 1024;
        }
        return width;
    }


Well, no. The HeadlessException gets

thrown when code that is dependent on a keyboard, display, or mouse is called in an environment that does not support a keyboard, display, or mouse.

There is no point in forcing a screen size inside an environment that does not have a screen.

In this case, the application should quit instead of reverting to a default value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜