Oracle® Data Provider for .NET Developer's Guide 11g Release 1 (11.1) Part Number B28375-01 |
|
|
View PDF |
The OracleException
class represents an exception that is thrown when the Oracle Data Provider for .NET encounters an error. Each OracleException
object contains at least one OracleError
object in the Error
property that describes the error or warning.
Class Inheritance
System.Object
System.Exception
System.SystemException
System.Runtime.InteropServices.ExternalException
(ADO.NET 2.0 only)
System.Data.Common.DbException
(ADO.NET 2.0 only)
Oracle.DataAccess.Client.OracleException
Declaration
// C# public sealed class OracleException : SystemException
Thread Safety
All public static methods are thread-safe, although instance methods do not guarantee thread safety.
Remarks
If there multiple errors, ODP.NET only returns the first error message on the stack.
Example
// C# using System; using System.Data; using Oracle.DataAccess.Client; class OracleExceptionSample { static void Main() { string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); // Create an OracleCommand object using the connection object OracleCommand cmd = con.CreateCommand(); try { cmd.CommandText = "insert into notable values (99, 'MyText')"; cmd.ExecuteNonQuery(); } catch (OracleException ex) { Console.WriteLine("Record is not inserted into the database table."); Console.WriteLine("Exception Message: " + ex.Message); Console.WriteLine("Exception Source: " + ex.Source); } } }
Requirements
Namespace: Oracle.DataAccess.Client
Assembly: Oracle.DataAccess.dll
Microsoft .NET Framework Version: 1.x or 2.0
See Also:
OracleException
members are listed in the following tables:
OracleException Static Methods
The OracleException
static method is listed in Table 5-57.
Table 5-57 OracleException Static Method
Method | Description |
---|---|
|
Inherited from |
OracleException Properties
OracleException
properties are listed in Table 5-58.
Table 5-58 OracleException Properties
Properties | Description |
---|---|
Specifies the TNS name that contains the information for connecting to an Oracle instance |
|
Specifies a collection of one or more |
|
|
Inherited from |
|
Inherited from |
Specifies the error messages that occur in the exception |
|
Specifies the Oracle error number |
|
Specifies the stored procedure that cause the exception |
|
Specifies the name of the data provider that generates the error |
|
|
Inherited from |
|
Inherited from |
OracleException Methods
OracleException
methods are listed in Table 5-59.
Table 5-59 OracleException Methods
Methods | Description |
---|---|
|
Inherited from |
|
Inherited from |
|
Inherited from |
Sets the serializable |
|
|
Inherited from |
Returns the fully qualified name of this exception |
The OracleException
static method is listed in Table 5-60.
Table 5-60 OracleException Static Method
Method | Description |
---|---|
|
Inherited from |
OracleException
properties are listed in Table 5-61.
Table 5-61 OracleException Properties
Properties | Description |
---|---|
Specifies the TNS name that contains the information for connecting to an Oracle instance |
|
Specifies a collection of one or more |
|
|
Inherited from |
|
Inherited from |
Specifies the error messages that occur in the exception |
|
Specifies the Oracle error number |
|
Specifies the stored procedure that cause the exception |
|
Specifies the name of the data provider that generates the error |
|
|
Inherited from |
|
Inherited from |
This property specifies the TNS name that contains the information for connecting to an Oracle instance.
Declaration
// C# public string DataSource {get;}
Property Value
The TNS name containing the connect information.
This property specifies a collection of one or more OracleError
objects that contain information about exceptions generated by the Oracle database.
Declaration
// C# public OracleErrorCollection Errors {get;}
Property Value
An OracleErrorCollection
.
Remarks
The Errors
property contains at least one instance of OracleError
objects.
Overrides Exception
This property specifies the error messages that occur in the exception.
Declaration
// C# public override string Message {get;}
Property Value
A string
.
Remarks
Message
is a concatenation of all errors in the Errors
collection. Each error message is concatenated and is followed by a carriage return, except the last one.
This property specifies the Oracle error number.
Declaration
// C# public int Number {get;}
Property Value
The error number.
Remarks
This error number can be the topmost level of error generated by Oracle and can be a provider-specific error number.
This property specifies the stored procedure that caused the exception.
Declaration
// C# public string Procedure {get;}
Property Value
The stored procedure name.
Overrides Exception
This property specifies the name of the data provider that generates the error.
Declaration
// C# public override string Source {get;}
Property Value
The name of the data provider.
OracleException
methods are listed in Table 5-62.
Table 5-62 OracleException Methods
Methods | Description |
---|---|
|
Inherited from |
|
Inherited from |
|
Inherited from System. |
Sets the serializable |
|
|
Inherited from |
Returns the fully qualified name of this exception |
Overrides Exception
This method sets the serializable info
object with information about the exception.
Declaration
// C# public override void GetObjectData(SerializationInfo info, StreamingContext context);
Parameters
info
A SerializationInfo
object.
context
A StreamingContext
object.
Remarks
The information includes DataSource
, Message
, Number
, Procedure
, Source
, and StackTrace
.
Overrides Exception
This method returns the fully qualified name of this exception, the error
message in the Message
property, the InnerException.ToString()
message, and the stack trace.
Declaration
// C# public override string ToString();
Return Value
The string representation of the exception.
Example
// C# using System; using Oracle.DataAccess.Client; class ToStringSample { static void Main() { string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); // Create an OracleCommand object using the connection object OracleCommand cmd = con.CreateCommand(); try { cmd.CommandText = "insert into notable values (99, 'MyText')"; cmd.ExecuteNonQuery(); // This will throw an exception } catch (OracleException ex) { Console.WriteLine("Record is not inserted into the database table."); Console.WriteLine("ex.ToString() : " + ex.ToString()); } } }