Throw exceptions only in debug mode in Java

Even if there are problems, I want to avoid collapse That's why I don't want to throw exceptions that I know won't be handled

public static void unexpectedException(String string,Exception e) {
    if (Build.DEBUG) {
        MyApp.errorLog(string);
        throw new RuntimeException(e);
    } else
        MyApp.errorLog(string,e);
}

Solution

If you don't want to use assertions like you really do, you can derive your exception from runtimeException Then, you don't have to declare them as throws. In the method header@ H_ 419_ 8@

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>