Click here to Skip to main content
15,916,462 members
Home / Discussions / C#
   

C#

 
AnswerRe: display a file to the browser using stream Pin
Heath Stewart20-Jan-06 12:12
protectorHeath Stewart20-Jan-06 12:12 
GeneralRe: display a file to the browser using stream Pin
CodyGen20-Jan-06 12:49
CodyGen20-Jan-06 12:49 
GeneralRe: display a file to the browser using stream Pin
Heath Stewart20-Jan-06 15:12
protectorHeath Stewart20-Jan-06 15:12 
QuestionBindingNavigator's AddNew vs. AutoIncrement DB fields Pin
mrlucmorin20-Jan-06 9:18
mrlucmorin20-Jan-06 9:18 
AnswerRe: BindingNavigator's AddNew vs. AutoIncrement DB fields Pin
Guffa20-Jan-06 9:57
Guffa20-Jan-06 9:57 
GeneralRe: BindingNavigator's AddNew vs. AutoIncrement DB fields Pin
mrlucmorin20-Jan-06 10:45
mrlucmorin20-Jan-06 10:45 
GeneralRe: BindingNavigator's AddNew vs. AutoIncrement DB fields Pin
Dave Kreskowiak20-Jan-06 11:28
mveDave Kreskowiak20-Jan-06 11:28 
QuestionHow do I create dynamic content (has to be easy!) Pin
Roger Jane20-Jan-06 8:33
Roger Jane20-Jan-06 8:33 
AnswerRe: How do I create dynamic content (has to be easy!) Pin
Guffa20-Jan-06 9:07
Guffa20-Jan-06 9:07 
GeneralRe: How do I create dynamic content (has to be easy!) Pin
Roger Jane20-Jan-06 22:39
Roger Jane20-Jan-06 22:39 
QuestionHow to copy a picture??? Pin
CrazyDragon638420-Jan-06 8:26
CrazyDragon638420-Jan-06 8:26 
AnswerRe: How to copy a picture??? Pin
Wjousts20-Jan-06 9:26
Wjousts20-Jan-06 9:26 
AnswerRe: How to copy a picture??? Pin
CodyGen20-Jan-06 9:44
CodyGen20-Jan-06 9:44 
AnswerRe: How to copy a picture??? Pin
CrazyDragon638420-Jan-06 23:23
CrazyDragon638420-Jan-06 23:23 
GeneralRe: How to copy a picture??? Pin
CodyGen21-Jan-06 3:45
CodyGen21-Jan-06 3:45 
QuestionDataGridViewColumn DefaultCellStyle help Pin
Kasdoffe20-Jan-06 7:59
Kasdoffe20-Jan-06 7:59 
QuestionCalling Visual Basic .net class object in C# Pin
idreesbadshah20-Jan-06 7:33
idreesbadshah20-Jan-06 7:33 
AnswerRe: Calling Visual Basic .net class object in C# Pin
Dave Kreskowiak20-Jan-06 7:39
mveDave Kreskowiak20-Jan-06 7:39 
Questionwhy can't i start/stop separate threads inside of same block? Pin
WetRivrRat20-Jan-06 5:47
WetRivrRat20-Jan-06 5:47 
AnswerRe: why can't i start/stop separate threads inside of same block? Pin
Le centriste20-Jan-06 6:03
Le centriste20-Jan-06 6:03 
AnswerRe: why can't i start/stop separate threads inside of same block? Pin
Dave Kreskowiak20-Jan-06 6:25
mveDave Kreskowiak20-Jan-06 6:25 
GeneralRe: why can't i start/stop separate threads inside of same block? Pin
WetRivrRat20-Jan-06 7:50
WetRivrRat20-Jan-06 7:50 
QuestionError handling - which is preferrable? Pin
Judah Gabriel Himango20-Jan-06 5:25
sponsorJudah Gabriel Himango20-Jan-06 5:25 
I'm calling a method that can throw one of several exceptions:

byte[] ReadFile(string filePath)
{
   return File.ReadAllBytes(filePath);
}


When calling this method, do you guys usually catch every possible exception, or just cover it with a single catch block? For example, do you do this:

string errorMessage = null;
            try
            {
                return File.ReadAllBytes(filePath);
            }
            catch (ArgumentException argumentError)
            {
                errorMessage = argumentError.Message;
            }
            catch (ArgumentNullException nullArgumentError)
            {
                errorMessage = nullArgumentError.Message;
            }
            catch (PathTooLongException pathError)
            {
                errorMessage = pathError.Message;
            }
            catch (DirectoryNotFoundException directoryNotFoundError)
            {
                errorMessage = directoryNotFoundError.Message;
            }
            catch (IOException ioError)
            {
                errorMessage = ioError.Message;
            }
            catch (UnauthorizedAccessException unauthorizedError)
            {
                errorMessage = unauthorizedError.Message;
            }
            catch (FileNotFoundException fileNotFoundError)
            {
                errorMessage = fileNotFoundError.Message;
            }
            catch (NotSupportedException notSupportedError)
            {
                errorMessage = notSupportedError;
            }
            catch (System.Security.SecurityException securityError)
            {
                errorMessage = securityError;
            }

            if(errorMessage != null)
            {
                MessageBox.Show(errorMessage, ...);
            }


Or do you catch it all in a single System.Exception catch block?

try
{
    File.ReadAllBytes(filePath);
}
catch(Exception ex)
{
    MessageBox.Show(ex.Message, ...);
}


Obviously the latter is easier to read and write, but the former is more precise and won't eat up things like system errors (OutOfMemoryException, OverflowException, etc.). Which do you guys suggest?

Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Little House on the Flickr
Judah Himango


AnswerRe: Error handling - which is preferrable? Pin
Colin Angus Mackay20-Jan-06 5:34
Colin Angus Mackay20-Jan-06 5:34 
GeneralRe: Error handling - which is preferrable? Pin
Werdna20-Jan-06 6:14
Werdna20-Jan-06 6:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.