javauis/m2g_qt/javasrc/com/nokia/microedition/m2g/M2GRunnableQt.java
author hgs
Fri, 29 Oct 2010 11:49:32 +0300
changeset 87 1627c337e51e
parent 56 abc41079b313
permissions -rw-r--r--
v2.2.21_1

/*
* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
*
*/

package com.nokia.microedition.m2g;

/**
 * Class that wraps runnable in order to catch and forward
 * exceptions that occured when executing in UI thread.
 * This class is used only for running native methods in UI thread.
 */
abstract class M2GRunnableQt implements Runnable
{
    private Throwable e = null;

    /**
     * From Runnable interface
     */
    public void run()
    {
        try
        {
            doRun();
        }
        catch (Throwable t)
        {
            e = t;
        }
    }

    /**
     * Checks for possible exceptions and errors and throws them forward.
     * Only unchecked exceptions and errors are thrown as only checked
     * exception that m3gcore may throw comes from loader which is not
     * executed in UI thread
     *
     * @throws RuntimeException
     * @throws Error
     */
    public void checkAndThrow()
    {
        if (e == null)
        {
            return;
        }
        if (e instanceof RuntimeException)
        {
            throw(RuntimeException)e;
        }
        else if (e instanceof Error)
        {
            throw(Error)e;
        }
    }

    /**
     * Method to be implemented for the UI thead execution
     */
    abstract void doRun();
}