Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

checkPermission without SecurityException?

 
Johan Nagels
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to check for a permission without running the risk of an Exception being thrown?
I would like to be able to check the permissions and change the GUI accordingly, but I don't like the idea of catching a lot of Exceptions.

Johan
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could encapsulate the checking and try/catch in a method which just returns a boolean. The SecurityManager.checkPermission(Permission) method would help with this.
 
Johan Nagels
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.
But that's what I would like to avoid: creating the exception takes up unnecessary cpu. I would prefer to have a method that does not cause/use an excaption at all.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could perform those checks once at startup, and store the results as booleans for later use.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic