title: How to insert the error message in table
body: <p>I am working on a project, in my project I am stuck in a scenario, where i need to maintain a error log. I created a <code>error log</code> table in which i have column name <code>Error Message</code>. I want to insert the error message in that column.for ex I am using a identity column, now if someone insert a value for that identity column without using "Set Identity On" then a error message is displayed like "Cannot insert explicit value for identity column in table 'example' when IDENTITY_INSERT is set to OFF." i want that error message to be as record in my table.</p>
  
  <p>Table Structure</p>
  
  <pre><code>create table example
  (
    id int identity(1,1),
    code int not null,
    startdate date not null,
    enddate date null,
    CONSTRAINT [PK_example] PRIMARY KEY CLUSTERED 
    (
      [id] ASC
    ),
  
    constraint uc_combination UNIQUE(code,startdate,enddate)
  )on [primary]
  </code></pre>
  
  <p>Error Log Table</p>
  
  <pre><code>Create table errorlog
  (
    errorid int identity (1,1),
    Errordate datetime,
    ErrorMessage Nvarchar(255)
  ) on [primary]
  </code></pre>
  
  <p>In Errorlog table in column error message i want to show those error message which occur while inserting the records in example table.</p>
  
  <p>How should I achieve that.</p>
  
  <p>Your help will be appreciable.</p>
  
  <p>Thanks</p>