开发者

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

开发者 https://www.devze.com 2023-02-14 08:44 出处:网络
private int getScreenWidth(){ int width; try{ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    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

精彩评论

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

关注公众号