I have the following method in my code:
bool TDefineEventForm::isValidTime(String time)
{
try
{
if (time.Length() < 7)
{
return false;
}
time = time.Trim();
int colPos = time.AnsiPos(":");
String hr = time.SubString(0,colPos-1);
String min = time.SubString(colPos+1,2);
int len = time.Length();
String ampm = time.SubString(len-1,2);
if ((ampm.LowerCase()!="am")&&(ampm.LowerCase()!"pm"))
{
return false;
}
hr.ToInt();
min.ToInt();
}
catch (const EConvertError &E)
{
return false;
}
catch (...)
{
return false;
}
return true;
}
The problem is that neither one of my catch blocks will catch the exception if the ToInt() methods throw an exception. It always terminates my application, and tells me that a EConvertError was raised by ToInt(). Can anyone see a problem with what I'm doing? Using C++ builder 6.
Thanks!
bool TDefineEventForm::isValidTime(String time)
{
try
{
if (time.Length() < 7)
{
return false;
}
time = time.Trim();
int colPos = time.AnsiPos(":");
String hr = time.SubString(0,colPos-1);
String min = time.SubString(colPos+1,2);
int len = time.Length();
String ampm = time.SubString(len-1,2);
if ((ampm.LowerCase()!="am")&&(ampm.LowerCase()!"pm"))
{
return false;
}
hr.ToInt();
min.ToInt();
}
catch (const EConvertError &E)
{
return false;
}
catch (...)
{
return false;
}
return true;
}
The problem is that neither one of my catch blocks will catch the exception if the ToInt() methods throw an exception. It always terminates my application, and tells me that a EConvertError was raised by ToInt(). Can anyone see a problem with what I'm doing? Using C++ builder 6.
Thanks!