Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Movie() throws Exception?



On Jul 17, 2005, at 4:44 PM, Elliotte Harold wrote:

I notice that the no-args Movie() constructor is declared to throw a QTException. Any idea why? i.e. in what circumstances would

Movie m = new Movie();

fail?

Among others, if you try the above without initializing QuickTime via QTSession.open():

import quicktime.*;
import quicktime.std.movies.*;

public class TrivialQTCrash {

    public static void main (String[] arrrImAPirate) {
        try {
            new Movie(); // die die die
        } catch (QTException qte) {
            qte.printStackTrace();
        }
    }
}

produces:

[chrisg5:~/dev/experiments/trivialqtcrash] cadamson% java TrivialQTCrash
Exception in thread "main" java.lang.ExceptionInInitializerError
        at quicktime.std.movies.Movie.allocate(Movie.java:394)
        at quicktime.std.movies.Movie.<init>(Movie.java:384)
        at quicktime.std.movies.Movie.<init>(Movie.java:372)
        at TrivialQTCrash.main(TrivialQTCrash.java:8)
Caused by: quicktime.QTNullPointerException: QuickTime MUST be initialized:quicktime.qd.QDGraphics
        at quicktime.QTObject._ID(QTObject.java:75)
        at quicktime.qd.QDGraphics.isOffscreen(QDGraphics.java:482)
        at quicktime.qd.QDGraphics.<init>(QDGraphics.java:333)
        at quicktime.qd.QDGraphics.<init>(QDGraphics.java:427)
        at quicktime.qd.QDGraphics.<clinit>(QDGraphics.java:56)
        ... 4 more
[chrisg5:~/dev/experiments/trivialqtcrash] cadamson%

Generally speaking, the Movie constructor throws an exception if the native NewMovie function returns NIL.  From the native docs:

function result
The identifier for the new movie. If NewMovie fails, the returned identifier is set to NIL. You can use GetMoviesError to obtain the error result, or noErr if there was no error. See Error Codes.

The genericized QTException-throwing seen throughout QTJ represents a wrapping of the handling of return values (the classic "if err != noErr" you see in QT sample code) and lookup of error codes.

If it seems weird that you have to catch QTException on pretty much any QTJ call, just imagine if you had to catch all the RuntimeExceptions in Java.  My point being that in theory, almost any call can potentially error (e.g., illegal access, out of memory, stack-heap collision), and this is more visible in native QT than it is in Java.  Maybe QTJ is more of a QT mindset than a Java mindset in this regard..

--Chris

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
QuickTime-java mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quicktime-java/email@hidden

This email sent to email@hidden

References: 
 >Movie() throws Exception? (From: Elliotte Harold <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.