Dave Carpeneto
Dave Carpeneto

Reputation: 1080

Accessing ResourceException in Eclipse?

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

Answers (1)

greg-449
greg-449

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

Related Questions