|
Looks different, but not so much better that I will change my code. Thanks anyway.
|
|
|
|
|
OK, but leave out the else - it's extraneous.
/ravi
|
|
|
|
|
If you're just logging the exception, why do you need an exception handler here at all? Just use the one 'further up the callstack'.
Regards,
Rob Philpott.
|
|
|
|
|
Because of other code to be executed or not. Something like this:
public ReturnType APublicFunction(some params)
{
try
{
SomeType someValue = aPrivateFunction(other params);
}
catch(Exception ex)
{
}
}
private SomeType aPrivateFunction(other params)
{
SomeFunction();
}
In case of the UserTriedToCheatException, it has to be handled in APublicFunction, and no more other code needs to be executed, while in other cases, the exceptions are not such important, the rest of the functions can still be executed (sufficient fallback functionality provided).
|
|
|
|
|
How about something similar to the way TryParse[^] works?
if (SomePrivateFunction(out SomeType SomeParamName))
{
}
Bastard Programmer from Hell
|
|
|
|
|
you can always invoking a Delegate, which will call the registered private method
Satish
|
|
|
|
|
Bernhard Hiller wrote: That catch-throw looks so terrible.
In my opinion, it won't look so terrible with some good comments around it!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Could you please clarify the meaning of up in the hierarchy or the use case where you need such type of exception handling?
I am asking this only because I thing your approach could be wrong?
well even I could be thinking wrong as well
Happy Coding
|
|
|
|
|
For example: a program starts. Many configuration and option files are read, server connections established etc. Some problems might arise, but fallback mechanisms are provided for many cases. But somewhere down in a function, a manipulation of the license is detected - that must be raised to the topmost level, the user must be told "You bad user $€$€!" and the program shuts down immediately.
|
|
|
|
|
Ok got it!
Do following things
1. Build two separate hierarchies for exception
1.1 For exception that you want to catch log e.g. LoggableException
1.2 For exception that you want to you caller to handle e.g. NonLoggableExcptions
2. Only catch the LoggableException exceptions - log in your case
3. Don not catch NonLoggableExcptions - these will be automatically traverse to the caller
4. The try block code should only throw these two exceptions or the derived objects from these exceptions
5. Don not catch Exception, its a bad practice, which says anything could be happen in the code. can it be . this gives bad impression. though I am not sure if any unhanded exception occurs how it is handled in the client server application as I never worked on it
hope this helps to you and solve you problem...
let me know if you need some further help
Happy Coding
modified 28-May-12 3:00am.
|
|
|
|
|
did this solution helped you?
|
|
|
|
|
How to block USB ports in c# application?
|
|
|
|
|
|
Hi,
I have a code to debug, which in delegate block as below.
Since even the F11 steps through it, i think of extracting method out of delegate.
I googled much about this with no ready-help.
private List<IProduct> GetPaginatedProduct(bool IsCalled, IProductPageSortOption paginationOption, IEnumerable<ICustomCriteria> additionalCriteria,string reportStartDate, string reportEndDate)
{
HibernateDelegate<IList<ProductStaticDataDBBean>> hibDel = delegate(ISession session)
{
....
....
}
}
My question is:
Can I call it like: say delegate(ISession session){ call some function(..) } .
So that I effectively replace inline code with a function call.
Please guide.
Thanks.
Edit: I was not able to break into anonymous code.
Refactoring the delegates to call few methods, containing anonymous code above, made task easier.
// ♫ 99 little bugs in the code,
// 99 bugs in the code
// We fix a bug, compile it again
// 101 little bugs in the code ♫
|
Tell your manager, while you code: "good, cheap or fast: pick two. "
modified 22-May-12 6:00am.
|
|
|
|
|
What you have here is an anonymous method, being assigned to a delegate.
I'm surprised that debugging isn't working, you should put a breakpoint inside the delegate to make sure. Stepping in should work. You can refactor quite easily:
HibernateDelegate<IList<ProductStaticDataDBBean>> hibDel = MeaningfulMethodName;
whateverreturntypeyouhave MeaningfulMethodName (ISession session)
{
....
....
}
Let me know if this answers your question, I think I may have the wrong end of the stick
|
|
|
|
|
I was not able to put a breakpoint inside anonymous code.
Refactoring the delegate to call few methods(and put anonymous code there) solved the problem and debugging.
// ♫ 99 little bugs in the code,
// 99 bugs in the code
// We fix a bug, compile it again
// 101 little bugs in the code ♫
|
Tell your manager, while you code: "good, cheap or fast: pick two. "
|
|
|
|
|
Ravi Sant wrote: I was not able to put a breakpoint inside anonymous code.
Curious: I tried it and it worked (VS2010 Ultimate), I don't remember there being a problem in VS 2008 but that doesn't mean there wasn't.
Sounds like something is Foo'd with VS.
|
|
|
|
|
If you put a stop point inside the delegate, it should get debugged as normal ... but when the delegate is called, not when it's defined (i.e. debugging the outer method will step over it because the content is not being executed at that time).
|
|
|
|
|
We are developing VMS.We found some difficulty in generating Barcode using Crystal report, We request you to send us the Barcode generator for Crystal report
|
|
|
|
|
Member 3601034 wrote: We request you to send us the Barcode generator for Crystal report
Sorry, but this site does not provide code to order.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
So a guy on my team accidentally left out a "return" statement in the following code:
public override OM.ModelObjectMessageSource CreateMessageSource(OM.ModelSolutionBase solution, OM.ModelObject item, OM.ModelObject referencedItem)
{
…..
TtTransitionPointer oTransitionPointer = item as TtTransitionPointer;
if (oTransitionPointer != null) new TransitionPointerMessageSource(oTransitionPointer);
…..
return base.CreateMessageSource(solution, item, referencedItem);
}
Easily enough found and fixed as it turned out, but we both were left puzzled that this wasn't a compiler warning. What's the use case for constructing the ephemeral object TransitionPointerMessageSource? It's not assigned to anything and isn't returned.
|
|
|
|
|
But you may be doing something in the instance that you create with the values you pass in. As this would be a perfectly reasonable thing to do, it would be churlish of the system to try and prevent it, and a warning could well be classed overkill as well.
|
|
|
|
|
Yea, I get that. Clearly there could be side effects of constructing an object, but would that be anything like reasonable programming practice? I mean, warnings are not errors. My expectation is that they point to something you might want to look at -- for example, a standalone statement that constructs an object which is then immediately (or at the leisure of the runtime system) disposed.
|
|
|
|
|
Tom Clement wrote: would that be anything like reasonable programming practice
Of course it would. In effect here, it's really no different to calling a static method in another class. I certainly wouldn't expect to be warned about it in the same way as I'm not warned if I ignore the return value from a method.
|
|
|
|
|
Simple: the constructor may do something that affects non-transient storage.
For example, it may insert the new object into the appropriate databases. That the object is not needed again by the code that creates it is irrelevant to the system.
It doesn't need a warning, any more than ignoring the return value from any other method call does:
private int MyMethod(int i)
{
i = i * 2;
Console.WriteLine (i);
return i;
}
...
MyMethod(6);
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|