在javame中拥有异常

时间:2011-02-16 08:48:30

标签: java java-me exception-handling

我可以用一个(自写)捕获替换所有捕获并在自编写的异常类型之间切换吗?这样我就可以轻松地在异常中进行调试。

try {
            int recordId = recordstore.addRecord(data, 0, data.length);

        } catch (RecordStoreFullException e) {
            e.printStackTrace();
                    System.out.println("debuginfo");
        } catch (RecordStoreNotOpenException e) {
            e.printStackTrace();
                    System.out.println("debuginfo");
        } catch (RecordStoreException e) {
            e.printStackTrace();
                    System.out.println("debuginfo");
        } catch (NullPointerException e) {
            e.printStackTrace();
                    System.out.println("debuginfo");
        } catch (Exception e) {
            e.printStackTrace();
                    System.out.println("debuginfo");
        }

1 个答案:

答案 0 :(得分:1)

你有什么理由不这样做吗?

try {
    int recordId = recordstore.addRecord(data, 0, data.length);

} catch (Exception e) {
    // or use a logging framework.
    System.err.println("debuginfo");
    e.printStackTrace();
}