Catching Java errors

前端 未结 4 904
栀梦
栀梦 2020-12-08 14:58

I\'ve heard that catching java.lang.Error is considered bad practice. I\'m currently loading a .dll that is not guaranteed to be on the PATH, and would like to

4条回答
  •  暖寄归人
    2020-12-08 15:13

    loadLibrary calls findLibrary() which would be helpful but it's protected, your best bet is to write your own class extending ClassLoader. Class loader has a protected method called findLibrary() which will return the path to a library or null if it doesn't exists. That way you can just check for null instead of catching errors. I'm not sure if this is actually "better" but it will remove your need for try catch;

提交回复
热议问题