Hi,

I have an Oracle stored procedure that will raise an application error
under certain conditions.  The actual errors raised may vary.

Whichever error I raise comes back as an OracleException.  I have not
found any 'number' property within the oracle exception to identify
exactly which error was thrown by my stored procedure. (The number is in
the message but parsing it seems messy).

In the code below, I have included 3 examples - the first one I don't want
to have to do, the second one seems more achievable and the third would be
the ideal but I've no idea how to do the second or third examples.


CODE
// Example 1 - last resort

try{
    db.ExecuteNonQuery(cmd);
} catch ( OracleException ex){

    if (ex.Message == "MyCustomError1"){
        // Do some stuff
    } elseif (ex.Message == "MyCustomError2"){
        // Do something else
    }

    //     and so on ...
}

// Example 2 - possible solution
// Not sure how to retrieve error number though

try{
    db.ExecuteNonQuery(cmd);
} catch ( OracleException ex){

    if (ex.Number == 1){
        // Do some stuff
    } elseif (ex.Number == 2){
        // Do something else
    }

    //     and so on ...
}

// Example 3 - would really like to have this, but
//  not sure how to map the custom oracle exception to
//  my exception class
public class CustomException1 : Exception{
    // Implementation ommitted
}

// Usage
try{
    db.ExecuteNonQuery(cmd);
} catch ( CustomException1 ex){
    // do something
} catch (CustomException2 ex){
    // do something else
}

Would be very gratefuul for any hints or tips.

Thanks,

Graeme

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to