Sometimes, I want to figure out where an NullReferenceException
(or the like) is thrown in my product's code without exposing any customer information. I have a tendency to do something like this (simplified example):
int flags = 0;
try{
SomeOperation(foo.bar);
flags |= 1 << 0;
SomeOtherOperation(bar.foo);
if (SomeCondition(baz.bar)){
flags |= 1 << 1;
stuff = bar.bar;
flags |= 1 << 2;
}
while(SearchForStuff(bar.foo, foo.bar)){
const int mask = (1 << 3) - 1;
flags &= mask;
flags |= 1 << 3;
if (StuffExists(foo.bar.foo)){
flags |= 1 << 4;
DoThings(foo);
}
}
flags |= 1 << 5;
Baz result = bar.foo.DoBar(foo);
flags |= 1 << 6;
return result;
}
catch (NullPointerException e){
SendCrashReport(e + " flags:" + flags);
}
My Question is is there a way to increment the bit shift at compile time such that one could add some logic and flag
increments without having to modify the bit shifts for the following flag
increments?
Edit: We are currently not including debugging symbols with the app, and I don't know if we ever will be.
Edit 2: I realized that |=
might be better than +=
for the case of 1 << 32
.