Hello,
I have an issue with the order of Exceptions. Currently my application just dies instead of handeling the one Exception it was supposed to catch, so I added additional try-catch statements to handle the errors.
Here is the outer part of the code
This function calls the WriteImage method on my Drive object. That function uses a library to access the hardware we use for talking to Cameras.
This is the code of that function
When I ran the code and pulled out a harddrive this is the errormessages I got, in sequence:
- AMAGAD SOMETHING UNKNOWN HAPPENED
- ErrorCode Returned = 58, M+NULL_ERROR = 0
- Caught an Exception
I don't understand why they come in this order....
I expected the following order of messages:
- ShowMessage()
- Caught an Exception
- AMAGAD.
I have an issue with the order of Exceptions. Currently my application just dies instead of handeling the one Exception it was supposed to catch, so I added additional try-catch statements to handle the errors.
Here is the outer part of the code
Code:
// We have to supply a new image ID because on every drive we
// rewrite from 0.
try
{
try
{
Path = DriveToUse->WriteImage(&TmpId, FileFormat, Buffer);
}
catch(std::exception &ex)
{
// Log the error message.
ShowMessage("Exception got caught");
// Logger::getSingletonPtr()->writeMsg(Ex.Message, 0, LOG_ERROR, true);
// Logger::getSingletonPtr()->writeLogMsg(Ex.Message, 0, LOG_ERROR, true, TDateTime::CurrentDate());
// Update the RecordId to skip over the following disk.
// If this is the last disk, then the recordID needs to
// be set to 0, else to the JumpPoint of the disk.
if(mDrives.back() == DriveToUse)
{
RingBuffer::Instance()->changeRecNr(0);
}
else
{
long NewId = CalculatePreviousJumpPoint(DriveToUse) + DriveToUse->MaximumImages();
RingBuffer::Instance()->changeRecNr(NewId);
}
// Call ourselves again, and try a new disk.
Path = WriteAnalogueImage(FileFormat, Buffer);
}
// Return true.
return Path;
}
catch(...)
{
ShowMessage("AMAGAD SOMETHING UNKNOWN HAPPENDED!");
}
}
This is the code of that function
Code:
AnsiString IO::Drive::WriteImage(long* RecordId, long FileFormat, MIL_ID Buffer)
{
// Call the MIL function to write the file.
// Save the complete path and return it later on.
AnsiString Path = AnsiString(DriveLetter()) + ":\\Images\\";
AnsiString Folder = AnsiString(IntToHex((int)(*RecordId / 0xFFF), 3)) + "\\";
AnsiString Filename = AnsiString(IntToHex((int)(*RecordId % 0xFFF), 3)) + ".jpg";
// Check if this directory exits, create it if it doesnt.
if(!DirectoryExists(Path + Folder))
{
ForceDirectories(Path + Folder);
}
// Export the buffer to the image.
// Try to save the data from the buffer to a file on the disk.
MbufExport((Path + Folder + Filename).c_str(), FileFormat, Buffer);
// Get the last error returned from the MIL system, this way we can check
// if the previous function executed properly.
long MilErrorCode = MappGetError(M_CURRENT, M_NULL);
// Check if an error occured. If the value is M_NULL_ERROR then no
// error occured with the last function call.
if(M_NULL_ERROR == MilErrorCode)
{
return (Path + Folder + Filename);
}
else
{
ShowMessage("ErrorCode returned = " + AnsiString(MilErrorCode) + " :: M_NULL_ERROR = " + AnsiString(M_NULL_ERROR));
// Writing failed. throw a new excption
// and mark ourselves as unusable.
SetUsable(false);
// Throw the exception so we can catch it in the manager.
throw new Exception("Failed to write the file to the disk. ErrorCode : " + AnsiString(MilErrorCode));
}
}
- AMAGAD SOMETHING UNKNOWN HAPPENED
- ErrorCode Returned = 58, M+NULL_ERROR = 0
- Caught an Exception
I don't understand why they come in this order....
I expected the following order of messages:
- ShowMessage()
- Caught an Exception
- AMAGAD.
Comment