SORU
26 Ocak 2009, PAZARTESİ


sonunda İstisna atar blokları

Zarif bir şekilde finally blok atılan özel durum işlemek için var mı?

Örneğin:

try {
  // Use the resource.
}
catch( Exception ex ) {
  // Problem with the resource.
}
finally {
   try{
     resource.close();
   }
   catch( Exception ex ) {
     // Could not close the resource?
   }
}

Nasıltry/catch finally blok kaçıyorsun?

CEVAP
26 Ocak 2009, PAZARTESİ


Ben genellikle bu gibi yapın:

try {
  // Use the resource.
} catch( Exception ex ) {
  // Problem with the resource.
} finally {
  // Put away the resource.
  closeQuietly( resource );
}

Başka bir yerde:

protected void closeQuietly( Resource resource ) {
  try {
    if (resource != null) {
      resource.close();
    }
  } catch( Exception ex ) {
    log( "Exception during Resource.close()", ex );
  }
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Alexey - servant of Christ

    Alexey - ser

    15 EYLÜL 2007
  • technodromeband's channel

    technodromeb

    28 NİSAN 2011
  • TecnoTutosPC

    TecnoTutosPC

    19 Kasım 2012