[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

How to handle errors in C++

I have a timer which loads a picture using ThePIctureName->LoadFromFile every x seconds. The only problem is , that the file i am trying to load is dynamically changing by another application( can be deleted in 1s, and be reconstructed the next sec) Therefore,at certain moments, my application presents error message that it cannot load the picture.

What I want is to create an event like this: WhenErrorOccures --> To ignore that error, and try to load the file again. How do i do this? Thanks.
0
Chrysaor
Asked:
Chrysaor
  • 2
  • 2
1 Solution
 
George TokasCommented:
Check first if(FileExists(FileName)) to see if the filename exists...
IF exists check the size - must be > 0 - and then try LoadFromFile...
Alternative:
try
{
  ThePIctureName->LoadFromFile()
  //your code for success here
}
catch(...)
{
 //Your code for failure
}

George Tokas.
0
 
Kent OlsenData Warehouse Architect / DBACommented:

I'd go with George's second suggestion (try/catch).  If the host file is changing quite often, just checking for the file may not be robust enough as the file can be deleted (or created) or its size change between checking for the file and actually trying to read it.


Good Luck,
Kent
0
 
ChrysaorAuthor Commented:
The try/catch didn't work.. An error did pop up again..
0
 
George TokasCommented:
I don't have a habbit to stop monitoring ANY Q I participate...
I'm and will be here Chrysaor...
What kind of error you have??

George Tokas.
0
 
Kent OlsenData Warehouse Architect / DBACommented:
>> The try/catch didn't work.. An error did pop up again..

Check your project settings.  It may be that this error is being handled by the default handlers.


Kent
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now