473,378 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Proper way to handle UnauthorizedAccessException

I have a project that gathers a list of directories on a computer.
When it hits hidden, protected directories (like c:\system volume
information) it throws an UnauthorizedAccessException error.

As a quick fix, I've captured that error in a try/catch block and just
ignored it (including ignoring the directory).

I don't like kludging like this. Is there a better way?

Thanks

-cbmeeks

Apr 16 '07 #1
7 4136
That doesn't sound like a kludge to me. You are catching a specific
error for a known, expected reason, and reacting accordingly. Sounds
fine IMO.

Marc
Apr 16 '07 #2
On Apr 16, 10:26 am, "Marc Gravell" <marc.grav...@gmail.comwrote:
That doesn't sound like a kludge to me. You are catching a specific
error for a known, expected reason, and reacting accordingly. Sounds
fine IMO.

Marc
Thanks.

I really didn't see any other way but I wanted to make sure.

Thanks again.

-cbmeeks

Apr 16 '07 #3
If there's nothing you can do, I would agree with Marc: you're handling the
exception.

Depending on the acces violation you could inform the user and ask for
another username/password; but then you'd have to deal with impersonation,
etc.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"cbmeeks" wrote:
On Apr 16, 10:26 am, "Marc Gravell" <marc.grav...@gmail.comwrote:
That doesn't sound like a kludge to me. You are catching a specific
error for a known, expected reason, and reacting accordingly. Sounds
fine IMO.

Marc

Thanks.

I really didn't see any other way but I wanted to make sure.

Thanks again.

-cbmeeks

Apr 16 '07 #4
On Mon, 16 Apr 2007 07:32:58 -0700, cbmeeks <cb*****@gmail.comwrote:
On Apr 16, 10:26 am, "Marc Gravell" <marc.grav...@gmail.comwrote:
>That doesn't sound like a kludge to me. You are catching a specific
error for a known, expected reason, and reacting accordingly. Sounds
fine IMO.

Marc

Thanks.

I really didn't see any other way but I wanted to make sure.
I agree with Marc. IHMO, the reason is *seems* kludgy is probably that
you're used to checking for error return codes and taking appropriate
action based on that. I mean, I don't know what your experience is, but
that's how it is for me. In the "olden days", the only time I ever dealt
with code that used any form of exception handling (setjmp/dojmp), the
exceptions were VERY exceptional. Basically for fatal failures only. We
still used return codes to indicate less-problematic failures, ones that
were benign or could be recovered from.

But .NET uses exceptions for practically any failure. An operation is
assumed to have succeeded, and if it doesn't it throws an exception. This
is just the normal way things work in .NET, and checking for a specific
exception and handling it gracefully is perfectly fine and appropriate.
(As Marc already said, I know :) ).

Anyway, that's not really all that pertinent...just sharing my own
difficulties in getting used to the .NET paradigm, in case they relate to
your own concerns in any way.

Pete
Apr 16 '07 #5
On Apr 16, 1:10 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Mon, 16 Apr 2007 07:32:58 -0700, cbmeeks <cbme...@gmail.comwrote:
On Apr 16, 10:26 am, "Marc Gravell" <marc.grav...@gmail.comwrote:
That doesn't sound like a kludge to me. You are catching a specific
error for a known, expected reason, and reacting accordingly. Sounds
fine IMO.
Marc
Thanks.
I really didn't see any other way but I wanted to make sure.

I agree with Marc. IHMO, the reason is *seems* kludgy is probably that
you're used to checking for error return codes and taking appropriate
action based on that. I mean, I don't know what your experience is, but
that's how it is for me. In the "olden days", the only time I ever dealt
with code that used any form of exception handling (setjmp/dojmp), the
exceptions were VERY exceptional. Basically for fatal failures only. We
still used return codes to indicate less-problematic failures, ones that
were benign or could be recovered from.

But .NET uses exceptions for practically any failure. An operation is
assumed to have succeeded, and if it doesn't it throws an exception. This
is just the normal way things work in .NET, and checking for a specific
exception and handling it gracefully is perfectly fine and appropriate.
(As Marc already said, I know :) ).

Anyway, that's not really all that pertinent...just sharing my own
difficulties in getting used to the .NET paradigm, in case they relate to
your own concerns in any way.

Pete
Thanks for the reply guys.

Now, I have to figure out how to read the entire contents (folders) of
the C:\ drive without it taking 30 seconds on a large drive...lol

cbmeeks

Apr 16 '07 #6
Now, I have to figure out how to read the entire contents (folders) of
the C:\ drive without it taking 30 seconds on a large drive...lol
How about "fdisk" ;-p

Marc

Apr 16 '07 #7
On Mon, 16 Apr 2007 12:12:28 -0700, cbmeeks <cb*****@gmail.comwrote:
[...]
Now, I have to figure out how to read the entire contents (folders) of
the C:\ drive without it taking 30 seconds on a large drive...lol
You can do that in only 30 seconds? Geez...I wish I had a computer that
fast. Or with so few directories. :)

Here's a solution for you: do it twice. The second time should be much
faster. :)
Apr 16 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Doug Taylor | last post by:
Hi, I originally posted this in dotnet.security, but have moved it here by request: Hi, I am trying to programmatically add a user with read permissions to the DACL of a registry key. ...
4
by: atv | last post by:
Whatis the proper way to handle errors from function calls? For example, i normally have a main function, with calls to mine or c functions. Should i check for errors in the functions called...
4
by: ASP Yaboh | last post by:
I have app that writes text files to any location of the users choosing in the network. It has been working for 18months. An exception has begun occurring where a folder on a network share is...
2
by: GM | last post by:
Any help is greatly appreciated! I'm up against a meeting deadline. Directory.CreateDirectory Method throws UnauthorizedAccessException Here is the path: ...
1
by: Hal 9000 | last post by:
In c# we have a function that creates a virtual directory in IIS 6.0 using DirectoryServices API. The code looks like this: // log in to IIS DirectoryEntry rootDir = new...
12
by: Lucas Tam | last post by:
I have a very simple loop: If (Directory.Exists(tempDirectory)) Then Try Dim Files() As String = Directory.GetFiles(tempDirectory) 'Clear out directory For Each Filename As String In Files...
0
by: nime | last post by:
I've got a problem. I cannot debug my app. which one contains WebBrowser control. I found a resolution but it's for an ASP related problem. I couldn't find a correct "user" to give permisson then...
0
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
I read from a serialport using a worker thread. Because the worker thread t does not loop often, I cannot wait to terminate the worker thread using a boolean in the While condition. So I have a...
8
by: imukai | last post by:
I have a forms-based authentication application on our intranet - ASP.NET 3.5 (C#). For security purposes there is one specific .aspx file that we have enabled Integrated Windows Authentication...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.