MediaPlayer exceptions isn't caught ! (Borland Builder)

Hi,

I Program under Borland C++ Builder 3.
(Beginner but eager to learn)

When I load a file in the MediaPlayer (e.g. an AVI file) and next click a button that does : MediaPlayer->Close(), an exception occurs !!!!
!! and it can't be caught by try { } catch (...) {  }  ??!

I tried following code :

try {
       MediaPlayer->FileName = " " ;
       MediaPlayer->Open() ;
       // MediaPlayer->Close() ;  
       // Causes 'MCI device not loaded'  Exception !
       }
 catch (...) {
       Caption = IntToStr(MediaPlayer->Error) ;
       }

But there was already another file loaded and Opened !
Yet, when the Exception occurs, it should just be caught by the 'try' 'catch' routine, is it not !!?

Now the Exception window still pops up (Also outside Builder !!)

Any ideas on this !??
Why in is the &%$@@&*$$ exception not caught by the try { ... routine ??

Hope someone can help.
sneeuwAsked:
Who is Participating?
 
nietodConnect With a Mentor Commented:
thankyou.
0
 
nietodCommented:
Someone else can probably help you more with this.  But until they come along the problem, is that the exception you encountered is one of Windows's structured exceptions.  These are similar to C++'s exceptions, but they are not the same.  They must be caught using a different mechanism.  (they are language indipendant.)
0
 
nietodCommented:
I've never fooled wtih the windows structured exceptions, but the C++ code you would use would be like:
__try {
      MediaPlayer->FileName = " " ;
          MediaPlayer->Open() ;
          // MediaPlayer->Close() ;  
          // Causes 'MCI device not loaded'  Exception !    
    }
__except( GetExceptionCode() == ??????) {
      Caption = IntToStr(MediaPlayer->Error) ;
    }

The ???? is the exception code value you need to test for.  You might want to look up "structured exception handling" in the docs and see what you can find.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
yonatCommented:
In Visual C++, catch (...) also catches Windows structured exceptions. There is also a way to convert WSEs to C++ exceptions, but I never fooled with it...
0
 
nietodCommented:
I think what you do is to catch the WSE and then throw a C++ exception.  Like

try {
    __try {
           MediaPlayer->FileName = " " ;
               MediaPlayer->Open() ;
               // MediaPlayer->Close() ;    
               // Causes 'MCI device not loaded'  Exception !      
            }
     __except( GetExceptionCode() == ??????)
         {
            throw SomeCPlusPlusException;
         }
    }
    catch (...)
    {
          Caption = IntToStr(MediaPlayer->Error) ;
    }  

I'm surprised no one has answered this one yet.
0
 
sneeuwAuthor Commented:
Hi guys,

Thanks for the input so far.
I'll try some of the code you posted.

I hope to be able to tell you more tomorrow.
In the mean time, please keep on it ...
So far nobody really seems to know for sure.

Anyway ...
Again, ... thanks for the input !

Peter
0
 
yonatCommented:
Actually, I think you cen specify a function that gets called whenever a WSE is raised. You can make this function throw your own exceptions, and then ctch them using
    catch (MyException x) {/*...*/}

In any case, I tried, and the following line does catch WSEs:
    catch (...) {/*...*/}
0
 
sneeuwAuthor Commented:
Hi,

I looked up the syntax for catching WSE under Borland C++ Builder.  So I was able to write the following code (which compiles) :

try {
    try {
    MediaPlayer->FileName = " " ;
    MediaPlayer->Open() ;
    // Error is : No MCI device open
    }
    __except(EXCEPTION_EXECUTE_HANDLER) {
    Caption = "Windows Structured Exception caught" ;
    // Throw own exception
    // throw ("My own Exception") ; // With or without : has no effect
    }
}
catch (...) {
//
// Caption = "Exception caught" ;
}

The problem however still exists !!!
The exception IS caught (since the __except routine is executed (seen in Caption)).
However ... The popup Window with the error message "No MCI device open also Still pops up !!!
What next ??????

Peter
0
 
sneeuwAuthor Commented:
If I would write a routine to catch all the application's exceptions (an OnException routine), do you think I would be able to catch this nasty Exception ?????????


0
 
nietodCommented:
When does the pop-up appear?  before the exception is thrown?
0
 
sneeuwAuthor Commented:
I think AFTER the exception is thrown !
But how exactly can I make sure ?
0
 
nietodCommented:
Put a debugger breakpoint in the exception catching code.  Does the  deubgger stop in the catching code before or afte the message appears.  (does the debugger stop in the catching code at all--if not you aren't catching the exception.)

If the message appears after the exception is caught, you mus be retrhowing the exception somehow.  If the message appears before the  exception is caught, you either are catching too late or, more likely, the message is displayed before the exception is throw which means you are out of luck.
0
 
sneeuwAuthor Commented:
Hi guys,

THE PROBLEM IS SOLVED !

I found it to be a 'self-created' problem.
In fact the Exception occurred each time in another routine !
I had an OnNotify routine that 'of course' also was executed each time I 'Closed' the MediaPlayer.

I began to suspect something fishy when I now sometimes had two Exceptions in a row or suddenly No error at all.  Depending on the State of some other settings, the OnNotify handler would evoke no, one or more exceptions I hadn't thought of.

It was also your input 'Question : Error BEFORE or AFTER Exception' that got me searching somewhere else.

So, ...
- Sorry I put you up to the work you guys did.
- I learned something new (WSE) I had never heard of (I'm new in programming).
- You BOTH deserve a piece of the pie.  I suggest I give you both (yonat and nietod) 125 points !??
Can you live with that ?
One question though !  How do I assign points to you ?? (I've never done this !).

Thanks again,
Peter
0
 
nietodCommented:
Unfortunately, you can't split points.  only one expert can answer (and none has so far) a question and they will get the points when you grade it (unless you reject the answer.)  You must decide which expert (if any) is most deserving of the points and ask them to submit an "answer".  Or you can decide that no expert was deserving and delete the question.  The other option---if you have the points---is to have one expert answer here and get the points and ask a "dummy" question for the other expert to answer (with the expert's name on it.)
0
 
yonatCommented:
Dividing the points is not possible, I'm afraid. I suggest you ask nietod submit an answer, so you can give hime the points - his comments are the ones that actually helped you.
0
 
sneeuwAuthor Commented:
Ok,
Since Yonat approves, I suggest I give Nietod the 250 points.
Maybe Nietod can ask a dummy question that yonat can answer for 125 points !
So Nietod, submit your answer and I'll award you for it.

Regards,
Peter
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.