Java中Exception类的名称必须有Exception
后缀也描述它的抛出情况。现在我有大约主要外部存储两个异常类在Android
:带有长名称的类
/**
* Thrown when Application tries to access primary external storage and it is not
* available for write.This only depends on status of storage, for example media
* not mounted,bad mounted, or ... .
*/
public class PrimaryExternalStorageIsNotReadyToWriteException extends Exception {
...
}
/**
* Thrown when Application tries to write on a directory
* of primary external storage that needs
* {@link Manifest.permission#WRITE_EXTERNAL_STORAGE} permission but that
* permission has not granted to the Application.
*/
public class WriteToPrimaryExternalStoragePermisionException extends RuntimeException {
...
}
正如你看到的,名字很长,但我无法从名称中删除Exception
或PrimaryExternalStorage
。此外,我不想使用SecurityException
或其他现有的例外,因为这些例外是普遍的。我知道长名不被禁止,但使用和提醒他们很难。我唯一能想到的是创建名称为primaryexternalstorageexceptions
的包,并将名称更改为IsNotReadyToWriteException
和WritePermisionException
。但这是一个好方法吗?有没有更好的方法来避免这些长名字?
我看到这些名字没有错。 –
@jangroth感谢您的关注,我真的曾想过关于超类和子类,但不幸的是,一个扩展了'Exception',另一个扩展了'RuntimeException'.So我不能用这种方式。 – hasanghaforian