Click here to Skip to main content
15,912,329 members
Home / Discussions / C#
   

C#

 
QuestionHandler for all unhandled exceptions in a class? Pin
alanteigne18-Dec-07 9:47
alanteigne18-Dec-07 9:47 
GeneralRe: Handler for all unhandled exceptions in a class? Pin
eggsovereasy18-Dec-07 10:36
eggsovereasy18-Dec-07 10:36 
GeneralRe: Handler for all unhandled exceptions in a class? Pin
alanteigne18-Dec-07 11:56
alanteigne18-Dec-07 11:56 
GeneralRe: Handler for all unhandled exceptions in a class? Pin
martin_hughes18-Dec-07 12:14
martin_hughes18-Dec-07 12:14 
GeneralRe: Handler for all unhandled exceptions in a class? Pin
Mark Churchill18-Dec-07 14:24
Mark Churchill18-Dec-07 14:24 
GeneralRe: Handler for all unhandled exceptions in a class? Pin
Giorgi Dalakishvili18-Dec-07 19:40
mentorGiorgi Dalakishvili18-Dec-07 19:40 
GeneralRe: Handler for all unhandled exceptions in a class? Pin
alanteigne19-Dec-07 7:30
alanteigne19-Dec-07 7:30 
GeneralException Handling in Windows application. Pin
Shani Aulakh18-Dec-07 9:27
Shani Aulakh18-Dec-07 9:27 
Hi All,

I can't find any good examples of throwing exceptions. I have the following code. I want to include all the possible exceptions i can. Help me out on this. I am just moving away from console object and moving towards exception object.

public int DeleteFilesOlderThan(int Days, int Hrs, int Mins, string filter)
{
DateTime dt = GetRelativeDateTime(Days, Hrs, Mins);
ArrayList oldFilePaths = FilesOlderThan(dt, filter);
int count = 0;
string message = null;
foreach (string filePath in oldFilePaths)
{
try
{
File.Delete(filePath);
count++;
}
//* System.Exception is too general..I want something more like FileNotFoundException...any exception that can be related to my code
catch (Exception e)
{
message = "Unable to delete " + filePath + "\r\n";
message += String.Format("Reason: {0}", e.Message);
MessageBox.Show(message);
}
}
return count;
}

// Using GetRelativeDateTime as a private method instead of public however as it is only to be used internally
private static DateTime GetRelativeDateTime(int days, int hours, int minutes)
{
return DateTime.Now.AddDays(-days).AddHours(-hours).AddMinutes(-minutes);
}

public ArrayList FilesOlderThan(DateTime dt, string filter)
{
//m_FolderPath = @"C:\CsharpTempFolder";
// Using the supplied path
//DirectoryInfo directory = new DirectoryInfo(Directory.GetCurrentDirectory())
DirectoryInfo directory = new DirectoryInfo(m_FolderPath);
// Filter is applied to the directory.GetFiles method to get files of given extension
// get FileInfos for the files in the current directory matching the filter expression
FileInfo[] files = directory.GetFiles(filter);
//list to hold the result
ArrayList older = new ArrayList();
foreach (FileInfo file in files)
{
//if smaller (older) than the relative time
if (file.CreationTime < dt)
older.Add(file.FullName); //add it to the list
}
return older;
}
GeneralRe: Exception Handling in Windows application. Pin
pmarfleet18-Dec-07 10:23
pmarfleet18-Dec-07 10:23 
GeneralRe: Exception Handling in Windows application. Pin
Shani Aulakh18-Dec-07 10:34
Shani Aulakh18-Dec-07 10:34 
GeneralRe: Exception Handling in Windows application. Pin
pmarfleet18-Dec-07 10:46
pmarfleet18-Dec-07 10:46 
GeneralRe: Exception Handling in Windows application. Pin
Shani Aulakh18-Dec-07 10:56
Shani Aulakh18-Dec-07 10:56 
GeneralRe: Exception Handling in Windows application. Pin
pmarfleet18-Dec-07 11:01
pmarfleet18-Dec-07 11:01 
GeneralRe: Exception Handling in Windows application. Pin
Shani Aulakh18-Dec-07 11:13
Shani Aulakh18-Dec-07 11:13 
GeneralRe: Exception Handling in Windows application. Pin
pmarfleet18-Dec-07 11:20
pmarfleet18-Dec-07 11:20 
GeneralRe: Exception Handling in Windows application. Pin
Kalvin @ Work18-Dec-07 11:16
Kalvin @ Work18-Dec-07 11:16 
GeneralRe: Exception Handling in Windows application. Pin
Shani Aulakh18-Dec-07 11:21
Shani Aulakh18-Dec-07 11:21 
GeneralpropertyGrid control Pin
netJP12L18-Dec-07 8:59
netJP12L18-Dec-07 8:59 
GeneralRe: propertyGrid control Pin
Paul Conrad24-Dec-07 19:49
professionalPaul Conrad24-Dec-07 19:49 
Questiontrackbar value Pin
#Jet18-Dec-07 8:50
#Jet18-Dec-07 8:50 
GeneralRe: trackbar value Pin
Paul Conrad24-Dec-07 19:50
professionalPaul Conrad24-Dec-07 19:50 
GeneralRe: trackbar value Pin
#Jet28-Dec-07 8:52
#Jet28-Dec-07 8:52 
GeneralConvert to utf8??? [modified] Pin
Doan Quynh18-Dec-07 7:37
Doan Quynh18-Dec-07 7:37 
GeneralRe: Convert to utf8??? Pin
Paul Conrad24-Dec-07 19:51
professionalPaul Conrad24-Dec-07 19:51 
QuestionLocate a treenode in a treeview Pin
gapfulgence18-Dec-07 7:31
gapfulgence18-Dec-07 7:31 

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.