We help IT Professionals succeed at work.

MediaPlayer exceptions isn't caught ! (Borland Builder)

sneeuw
sneeuw asked
on
Medium Priority
1,418 Views
Last Modified: 2008-02-01
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.
Comment
Watch Question

Commented:
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.)

Commented:
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.

Commented:
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...

Commented:
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.

Author

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

Commented:
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 (...) {/*...*/}

Author

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

Author

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 ?????????


Commented:
When does the pop-up appear?  before the exception is thrown?

Author

Commented:
I think AFTER the exception is thrown !
But how exactly can I make sure ?

Commented:
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.

Author

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

Commented:
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.)

Commented:
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.

Author

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
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.