Is “throws Exception” bad practice?

前端 未结 3 1138
后悔当初
后悔当初 2020-12-19 02:02

I\'m reviewing code for a colleague and I encounter a piece of code similar to this:

public X Foo1(Y y) throws Exception {
    X result = new X(y);
    resul         


        
3条回答
  •  遥遥无期
    2020-12-19 02:22

    This forces everybody using this method to handle thrown Exceptions.

    Even if you like using checked exceptions (which I don't) this leaves you with no information at all what kind of stuff might go wrong. So you can't really handle it in a meaningful way.

提交回复
热议问题