0

I have this piece of code :

try{
 // other instructions
    customer.Create(act.ID, act.AccountId.Value, act.AccountName, act.Referer);
 // other instructions
}
catch (Exception ex)
{
Logging.Trace(ex);
}

In some cases, AccountId is null, and getting the Value like that threw an InvalidOperationException.

My question is : in a catch section, is this possible to retrieve the fact that AccountId was null ?

Using StackTrace or, something like that. I search on google but nothing appears. As much as possible, I do not want to modify the structure of the code before, using if( Account != null) etc...

Thanks in advance for any kind of help.

Etienne Arthur
  • 680
  • 1
  • 9
  • 17
  • I don't see a `catch` or `try` or anything? Where is it? Inside the `.Create` method? – Arran Aug 08 '13 at 14:54
  • I've just edit the code to be more understandable. – Etienne Arthur Aug 08 '13 at 14:56
  • Why do you want to let the error happen, then catch it and have to find `AccountId` was null? Can't you change your code so that exception will be avoided? – Sriram Sakthivel Aug 08 '13 at 14:59
  • That' the requirement in fact : the code must be as is, and the exception must be happen if a problem appears. If it was up to me, i just rewrite the code :) – Etienne Arthur Aug 08 '13 at 15:02
  • 1
    The InvalidOperationException class has a constructor that takes a string. You ought to use that to make the exception more descriptive. If it is not your code then by all means add the code to check these arguments yourself. A null AccountId ought to generate, say, an ArgumentNullException – Hans Passant Aug 08 '13 at 15:34

0 Answers0