在asyncTask中捕获异常

时间:2016-06-09 08:20:14

标签: java android android-asynctask jmail

我正面临着这个问题。 我想发送一封电子邮件,我在AsyncTask类中创建代码。 但我无法捕获网络异常或任何异常。以下是我发送电子邮件的代码

$result = DB => collection('PMS')->raw(function ($collection){
    return $collection->aggregate(array(
        array( '$match' => array( "PanelID" => "A00898" ) ),
        array( '$project' => array( 'EventTS' => 1, 'MainsPower' => 1 ) ),
        array(
            '$unwind' => array(
                'path' => "$MainsPower",
                'includeArrayIndex' => "arrayIndex",
                'preserveNullAndEmptyArrays' => true
            )
        ),
        array(
            '$project' => array(
                '_id' => 0,
                'MainsPower' => 1,
                'timestamp' => array(
                    "$add" => array(
                        "$EventTS",
                        array( "$multiply" => array( 60000, "$arrayIndex" ) )
                    )
                )
            )
        )
    ));
});

GMailSender.java

public class SendMail extends AsyncTask<Void, Object, Void> {
    int count =0;


    @Override
    protected Void doInBackground(Void... voids) {
        GMailSender sender = new GMailSender("user@gmail.com", "password");
        try {
            sender.sendMail("[Quick Hide video]Backup password",
                    "Your backup password is: "+utils.getPassword(),
                    "user@gmail.com",
                    "thienvan.ptit@gmail.com");
        } catch (Exception e) {
            Log.d("Check","check");
            // the code does not run to this with network is not connect
        }
        return null;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        super.onPostExecute(aVoid);
        // do something
    }
}

任何人都可以帮助我在Asyntask中捕获异常 谢谢

0 个答案:

没有答案