Solved

How to handle errors in C++

Posted on 2008-10-03
5
208 Views
Last Modified: 2013-11-17
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
Comment
Question by:Chrysaor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
George Tokas earned 500 total points
ID: 22633776
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
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 22634448

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
 

Author Comment

by:Chrysaor
ID: 22644295
The try/catch didn't work.. An error did pop up again..
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 22645238
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
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 22649092
>> 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question