In the Java Server API, How Can I Trap a Permissions Error from a Work Item Save Operation?
I have a follow-up action that saves the work item. Sometimes this action will generate a permissions error. In those cases, I want the operation behavior to abort gracefully without interfering with the save operation. If the permissions error had been an exception, I could have caught it in a try-catch block. However, since a permissions error is something else, I'm not sure how to trap for that scenario and allow a graceful exit of the operation behavior.
|
Accepted answer
I should follow up on this post and provide some more details since I have the solution now. Ralph's answer set me on the correct path, but I just noticed this post in my search results and saw that the answer count was "0" which implied it was still unanswered. Rather than catching a generic throwable exception, I ultimately found that I needed to catch "PermissionDeniedException". Catching this exception allowed me to continue the operation behavior without failing the save operation. Ralph Schoon selected this answer as the correct answer
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.
Comments
Have you tried to catch Throwable? This is the super super class for exceptions as far as I know. You should be able to find out what is thrown, if anything. Otherwise do you check the status of the work item save?
I am not currently checking the status of the work item save. I'll give that a try. Thanks.
Edit: Unfortunately, neither of those suggestions has panned out. Got any other ideas?
Edit 2: Actually, I just realized that the permissions error is happening long before my saveWorkItem3 operation (it occurs when tracing links). I need to put the try/catch block earlier in the code. I'll try that and come back here.
Edit 3: Looks like the catch Throwable does the trick. Stack exchange seems to argue that it's bad practice to do that though so I guess I need to do some testing to figure out exactly which exception is being thrown for the permissions error. I'll mark your answer as the accepted solution.