Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 06-25-2011, 02:41 AM
Zaaka Zaaka is offline
Senior Member
 
Join Date: Aug 2002
Location: Teesside, UK
Posts: 217
Default problem catching jpg errors

I am trying to catch any jpg errors when trying to load a jpg, but Ikeep getting the following error.

Quote:
Class type required
occurs just after the 'do' after Exception

here is my current code:

Code:
Picture := TJpegimage.Create;
    TRY
      Picture.LoadFromFile(filelistbox1.items[t]);
    EXCEPT
    ON E: Exception do   renamefile(filelistbox1.items[t],changefileext(filelistbox1.items[t],'badjpg'));
I am trying to loop through a folder of 1000+ jpg's and want to rename any which are corrupted.

can any body help.
Reply With Quote
  #2  
Old 06-26-2011, 10:25 PM
DarkByte DarkByte is offline
Junior Member
 
Join Date: May 2011
Posts: 10
Default

Have you, by any chance, redeclared Exception to a non-class type ?
Reply With Quote
  #3  
Old 06-26-2011, 10:30 PM
Zaaka Zaaka is offline
Senior Member
 
Join Date: Aug 2002
Location: Teesside, UK
Posts: 217
Default problem catching jpg errors

No, this is the only place i have used it
Reply With Quote
  #4  
Old 06-27-2011, 09:15 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,335
Default

raise the exception, with this code I cannot see anything...
What is the value of "t", is this actually assigned, ChangeFileExt requires a '.' aswell, but this will not raise an error...
Reply With Quote
  #5  
Old 06-27-2011, 01:45 PM
Zaaka Zaaka is offline
Senior Member
 
Join Date: Aug 2002
Location: Teesside, UK
Posts: 217
Default problem catching jpg errors

Hi Norrit, Thanks for looking,

The 't' is from a FOR loop which is looping through a TFileListBox which has about 1000 jpgs in it and what I am trying to do is display the jpg (not visually) and if any jpgerrors occur mark it as a bad jpg, rename it for reporocessing at a later date.

I have tried from a few examples but I just get the same problem.
Reply With Quote
  #6  
Old 06-27-2011, 01:47 PM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,335
Default

Start simple, without the for-loop.. Should be something you're missing, but I cannot see because there's too little info given
Reply With Quote
  #7  
Old 06-27-2011, 01:54 PM
Zaaka Zaaka is offline
Senior Member
 
Join Date: Aug 2002
Location: Teesside, UK
Posts: 217
Default

This is the whole code that I am trying as it was sent to me.

Code:
procedure TForm1.CheckJpegs1Click(Sender: TObject);
VAR
t:integer;
tjpg: Tjpegimage;
oname,nname:string;
begin
for t:=0 to filelistbox1.items.count-1 do
BEGIN
  // Use polymorphic Picture since it will load all registered file types
  tjpg := TJpegimage.Create;
    TRY
      tjpg.LoadFromFile(filelistbox1.items[t]);
    EXCEPT
    On E: EInvalidGraphic do begin renamefile(filelistbox1.items[t],changefileext(filelistbox1.items[t],'badjpg'));end;
    end;
    tjpg.Free
  END;
  filelistbox1.update;
end;
I have been told that this should work
Reply With Quote
  #8  
Old 06-27-2011, 02:04 PM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,335
Default

Back to my original comment, display the error message instead of swallowing it and then call a rename...

FileListBox has no path in front, so most likely you'll get a "invalid path specified" error or something... In your except you again work with the invalid path and a new error occurs...

If that still isn't the issue, if it's not an EInvalidGraphic error the original error will be raised... Therefor, seeing this code it's unable to pinpoint where your error occurs...
Reply With Quote
Reply

Tags
catch, error, exception, jpg

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 06:26 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.