Home > .NET > Innermost Exception

Innermost Exception

seringkali exception yg kita tangkap tidak benar2 bisa menjelaskan apa yg harus dilakukan untuk mengatasi masalah tersebut. Karena pesan error yg dikeluarkan tidak jelas.

Saya melihat implementasi NServiceBus dimana exception yg di log oleh log4net jelas sekali tujuannya. Exception yg diambil adalah pesan yg terdalam dari exception tersebut.

Code dari NSB tersebut saya jadikan sebagai extensions method untuk Exception.

public static class ExceptionExtensions
    {
        public static Exception GetInnermostException(this Exception e)
        {
            var result = e;
            while (result.InnerException != null)
                result = result.InnerException;

            return result;
        }
    }
Advertisement
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: