c++ - How to handle JPEG #41 error -


i have project in c++ builder6. there's opendialog upload images project. i'd project safe , because accepts .jpg or .bmp images decided make restriction. far i'm concerned can recognize .jpg file setting stream reader 4th position. if find "jfif" here, it'll .jpeg file. , on. here's code

if(opendialog1->execute())  {     tfilestream *stream = new tfilestream(opendialog1->filename, fmopenread);     if(stream != null)      {         if(stream->size < 10)          {             delete stream;             return;         }         char str[10];         stream->read(str, 10);         if(ansistring(str + 6).setlength(4)=="jfif")         {             showmessage("it's jpeg");         }         else if ( ansistring(str).setlength(2)=="bm") {             showmessage("it's bmp");         }         else         {             showmessage("it can not downloaded");             return;         }     }     delete stream; } 

but unfortunately code raises exception jpeg error #41 when put here text file renamed extension.

enter image description here

so idea doesn't work. whole question is: can make program return error messages without using try-catch method?


by way, understand why exception being raised, because jpeg file empty. i'd handle using own system, not standart exception.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -