VC++ADO中异常码的有关问题

VC++ADO中错误码的问题
在VC中用ADO连接SQL   SERVER2000   数据库,   怎样才能捕捉到数据库返回的错误,比如记录已存在,键值重复等???

------解决方案--------------------
try
{
.....
}
catch(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());

// Print Com errors.
printf( "Error\n ");
printf( "\tCode = %08lx\n ", e.Error());
printf( "\tCode meaning = %s\n ", e.ErrorMessage());
printf( "\tSource = %s\n ", (LPCSTR) bstrSource);
printf( "\tDescription = %s\n ", (LPCSTR) bstrDescription);
}