Solved

MediaPlayer exceptions isn't caught ! (Borland Builder)

Posted on 1998-07-19
16
1,174 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.
0
Comment
Question by:sneeuw
  • 7
  • 6
  • 3
16 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1168124
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
 
LVL 22

Expert Comment

by:nietod
ID: 1168125
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
 
LVL 5

Expert Comment

by:yonat
ID: 1168126
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
 
LVL 22

Expert Comment

by:nietod
ID: 1168127
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
 

Author Comment

by:sneeuw
ID: 1168128
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
 
LVL 5

Expert Comment

by:yonat
ID: 1168129
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
 

Author Comment

by:sneeuw
ID: 1168130
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
 

Author Comment

by:sneeuw
ID: 1168131
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 22

Expert Comment

by:nietod
ID: 1168132
When does the pop-up appear?  before the exception is thrown?
0
 

Author Comment

by:sneeuw
ID: 1168133
I think AFTER the exception is thrown !
But how exactly can I make sure ?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1168134
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
 

Author Comment

by:sneeuw
ID: 1168135
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
 
LVL 22

Expert Comment

by:nietod
ID: 1168136
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
 
LVL 5

Expert Comment

by:yonat
ID: 1168137
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
 

Author Comment

by:sneeuw
ID: 1168138
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
 
LVL 22

Accepted Solution

by:
nietod earned 250 total points
ID: 1168139
thankyou.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now