SORU
29 EYLÜL 2008, PAZARTESİ


C doğal bir durum görebiliyor musunuz# kodu?

C# kodu yerel bir özel durum biraz yönetilmeyen kütüphanede derin atılan yakalayabilir misiniz? Farklı bir şey yapmak lazım yakalamak için ya da bir standart... ... yakalamak deneyin musunuz?

CEVAP
29 EYLÜL 2008, PAZARTESİ


Win32Exception kullanım ve NativeErrorCode özelliğini uygun şekilde işlemek için kullanabilirsiniz.

// http://support.microsoft.com/kb/186550
const int ERROR_FILE_NOT_FOUND = 2;
const int ERROR_ACCESS_DENIED = 5;
const int ERROR_NO_APP_ASSOCIATED = 1155; 

void OpenFile(string filePath)
{
    Process process = new Process();

    try
    {
        // Calls native application registered for the file type
        // This may throw native exception
    	process.StartInfo.FileName = filePath;
    	process.StartInfo.Verb = "Open";
    	process.StartInfo.CreateNoWindow = true;
    	process.Start();
    }
    catch (Win32Exception e)
    {
    	if (e.NativeErrorCode == ERROR_FILE_NOT_FOUND || 
    		e.NativeErrorCode == ERROR_ACCESS_DENIED ||
    		e.NativeErrorCode == ERROR_NO_APP_ASSOCIATED)
    	{
    		MessageBox.Show(this, e.Message, "Error", 
    				MessageBoxButtons.OK, 
    				MessageBoxIcon.Exclamation);
    	}
    }
}

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Jonathan D.

    Jonathan D.

    3 Kasım 2006
  • KittiesMama

    KittiesMama

    10 AĞUSTOS 2008
  • Marques Brownlee

    Marques Brow

    21 Mart 2008