小编Joe*_*Joe的帖子

有没有办法压缩Java Try Catch Blocks?

做了一些快速的研究后,我找不到任何部分因为我不确定我是否正在寻找正确的东西,部分是因为我认为没有.

但是,请告诉我是否有办法可以浓缩这一点.此外,我是Java的新手,如果你能用简单的术语解释你的变化及其作用,那也很棒!

try {
    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
            .getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            javax.swing.UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (ClassNotFoundException ex) {
    java.util.logging.Logger.getLogger(GameOfLife.class.getName()).log(
            java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(GameOfLife.class.getName()).log(
            java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(GameOfLife.class.getName()).log(
            java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(GameOfLife.class.getName()).log(
            java.util.logging.Level.SEVERE, null, ex);
}

java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
        new GameOfLife().setVisible(true);
    }
});
Run Code Online (Sandbox Code Playgroud)

java try-catch

1
推荐指数
1
解决办法
154
查看次数

标签 统计

java ×1

try-catch ×1