What are the best practices on catching COM-exception in C#? -


could you, please, tell me how handle com exceptions in c# in right way? example, using directorysearcher , getting comexception: server not operational. how should handle exception? can write handler comexception, how identify particular exception type? should examine exception message or hresult it?

you must hresult, is errorcode of exception instance, , therefore way know going on. can decypher hresult this , this article.

example:

try {     //your code } catch(comexception ex) {     int error = ex.errorcode;      //conditions , error handling } 

basically hresult 32 bit integer 2 significant bits describe sort of message (succes, info, warning, error). other 30 bits used describe rest of message.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -