I'm sorry if this seems like a really stupid question but I'm having problems getting to grips with exception handling. I need to handle disk full exceptions in a specific manner. I understand that I can catch a group of errors with e.g.
catch(IOException e){ ...}
but the question I have is how do I determine that its a disk full error? The only way I can see is something like:
catch (Exception e) {
if (e.getMessage().equals("There is not enough space on the disk")){
// Disk full handler
...
}
else {
//General purpose exception handler
...
}
But this seems fraught with problems of localization and error text that's liable to change. I'd have thought that something like:
catch(DiskFullException e)
would be possible but I can only find a relatively small number of exceptions that can be explicitly handled in this way.
Am I missing something, is my approach the only one or is there some deeper philosophy that I've missed?
Many thanks in advance for any enlightenment.