Reputation: 1080
I'm doing something in an Eclipse plugin that throws a ResourceException. I in turn need to know what the path of the resource involved is.
I can do this via ((ResourceStatus) caughtException.getStatus()).getPath()
, however I then get admonished with Discouraged access: The type 'ResourceException' is not API
(same warning for ResourceStatus
). Should I just ignore the warning, or is there a better way for me to get the path? I'm just worried that this might change later on.
Technically I could extract the path from the exception's message, but that feels gross & have back luck with scraping data out of human-presentable strings :-/
Upvotes: 0
Views: 45
Reputation: 111142
ResourceException
extends CoreException
which is part of the official API so you can catch that.
ResourceStatus
implements IResourceStatus
which again is an official API.
So something like:
catch (CoreException ex) {
IStatus status = ex.getStatus();
if (status instanceof IResourceStatus) {
IPath path = ((IResourceStatus)status).getPath();
....
}
}
IResourceStatus
also contains the definitions of the error codes that IStatus.getCode
returns for a resource exception.
Upvotes: 1