how you can get the native error code of an exception in .net

0

As is known, the same exception can be detonated in multiple ways, an example of this IOException that starts when there is a NetworkStream timeout or when the host of a TcpClient is disconnected. What I need is a way to get the error code of each of these scenarios to be able to act in the right way. Greetings

    
asked by Gerardo Baeza 25.08.2017 в 01:45
source

2 answers

1

As you said, there are several types of exceptions depending on how they originate, you can have an IOException, SqlException ...

Some exceptions if they have a number that identifies them that can be obtained through their property number. An example of these is the SqlException that has a property called Number.

Other exceptions such as InvalidOperationException does not have the Number property, you can access its Message property to see the explanation of the exception.

I hope it serves you.

    
answered by 25.08.2017 в 09:34
0

I do not know if you mean the Message property of the Exception class:

try{

//código donde puede saltar una excepción 

catch (Exception e){
   string error =  e.Message;
}

link

    
answered by 25.08.2017 в 09:04