Skip to main content
handle error
Source Link
djeeg
  • 6.8k
  • 3
  • 27
  • 28

Custom exceptions should be used to define different types of exception.

  • Exceptions from the database
  • Exceptions from file io
  • Exceptions from web services

They should be very simple, and contain no other logic than assigning variables. Why? Because if the exception constructor throws another exception you are going to have a hard time tracing it.

The ways i handle those exceptions are:

  1. AOP (Spring.NET)
  2. Specific try/catches
  3. The global exception handler

In a program

namespace ConsoleApplication1 {
    class Program {
        static void Main(string[] args) {
            try {
                //do something
            } catch(Exception e) {
                //log error
            }
        }
    }
}

Or in a web site

public class ApplicationErrorModule : IHttpModule {

    public void Init(HttpApplication context) {
        context.Error += new EventHandler(context_Error);
    }

    private void context_Error(object sender, EventArgs e) {
        //log error
    }
}

Custom exceptions should be used to define different types of exception.

  • Exceptions from the database
  • Exceptions from file io
  • Exceptions from web services

They should be very simple, and contain no other logic than assigning variables. Why? Because if the exception constructor throws another exception you are going to have a hard time tracing it.

Custom exceptions should be used to define different types of exception.

  • Exceptions from the database
  • Exceptions from file io
  • Exceptions from web services

They should be very simple, and contain no other logic than assigning variables. Why? Because if the exception constructor throws another exception you are going to have a hard time tracing it.

The ways i handle those exceptions are:

  1. AOP (Spring.NET)
  2. Specific try/catches
  3. The global exception handler

In a program

namespace ConsoleApplication1 {
    class Program {
        static void Main(string[] args) {
            try {
                //do something
            } catch(Exception e) {
                //log error
            }
        }
    }
}

Or in a web site

public class ApplicationErrorModule : IHttpModule {

    public void Init(HttpApplication context) {
        context.Error += new EventHandler(context_Error);
    }

    private void context_Error(object sender, EventArgs e) {
        //log error
    }
}
Source Link
djeeg
  • 6.8k
  • 3
  • 27
  • 28

Custom exceptions should be used to define different types of exception.

  • Exceptions from the database
  • Exceptions from file io
  • Exceptions from web services

They should be very simple, and contain no other logic than assigning variables. Why? Because if the exception constructor throws another exception you are going to have a hard time tracing it.