Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle UnauthorizedAccessException from User Code

In a Windows Application I have, I am doing some changes in registry like deleting a particular key, in some test scenarios like in a Vista machine with its UAC put on, I'm getting System.UnauthorizedAccessException. My code would look something like this:

try
{
    //delete registry keys
}
catch (UnauthorizedAccessException ex)
{
    //handling
}
catch (Exception genEx)
{
    //handling
}

But the application would still go crashing., not being handled by the catch block. Is there some way I could handle it?

like image 208
Niranjan Avatar asked Dec 23 '11 15:12

Niranjan


1 Answers

You're probably throwing another exception from the catch block. Try commenting all lines in the catch block and it should work just fine.

like image 175
nemnem Avatar answered Oct 23 '22 04:10

nemnem