Click here to Skip to main content
15,895,370 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: Error handling - which is preferrable? Pin
Judah Gabriel Himango20-Jan-06 9:56
sponsorJudah Gabriel Himango20-Jan-06 9:56 
QuestiondataGrid & first row selection Pin
moonangel_bio20-Jan-06 5:00
moonangel_bio20-Jan-06 5:00 
AnswerRe: dataGrid & first row selection Pin
CodyGen20-Jan-06 5:42
CodyGen20-Jan-06 5:42 
AnswerRe: dataGrid & first row selection Pin
Drew McGhie20-Jan-06 9:22
Drew McGhie20-Jan-06 9:22 
GeneralRe: dataGrid & first row selection Pin
moonangel_bio21-Jan-06 1:34
moonangel_bio21-Jan-06 1:34 
QuestionClearing the DataTable Pin
dvsr20-Jan-06 4:21
dvsr20-Jan-06 4:21 
QuestionPower Point from C# code Pin
Bested20-Jan-06 2:57
Bested20-Jan-06 2:57 
QuestionHow to use Bass.Net.dll Pin
Divyang Mithaiwala20-Jan-06 2:41
Divyang Mithaiwala20-Jan-06 2:41 
AnswerRe: How to use Bass.Net.dll Pin
Colin Angus Mackay20-Jan-06 5:36
Colin Angus Mackay20-Jan-06 5:36 
GeneralRe: How to use Bass.Net.dll Pin
Divyang Mithaiwala20-Jan-06 6:25
Divyang Mithaiwala20-Jan-06 6:25 
GeneralRe: How to use Bass.Net.dll Pin
Dave Kreskowiak20-Jan-06 7:01
mveDave Kreskowiak20-Jan-06 7:01 
Questiondatagrid out of bound error,Plz help Pin
rudra08320-Jan-06 1:47
rudra08320-Jan-06 1:47 
QuestionDatagrid Selection ,Giving out of bound index error Pin
rudra08320-Jan-06 1:45
rudra08320-Jan-06 1:45 
QuestionHELP ME! SymbianOS and C# Pin
keisee20-Jan-06 1:43
keisee20-Jan-06 1:43 
Questionretrieve MAC address without SendARP Pin
ESTAN20-Jan-06 1:30
ESTAN20-Jan-06 1:30 

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.