|
Thanks, but I didn't need barcode generator, the thing that I need is a program (for example an ActiveX or DLL) which I be able to use them in my own
project. I will search more carefully through the
second link which u sent.
|
|
|
|
|
|
how do i use pdfbox in c#??
|
|
|
|
|
|
In a function, I want to catch all exceptions and just log them (they do not really matter), but one specific type of exception must not be handled like this - it must be dealt with in a function farther up the call stack.
Currently, I do something like this:
private void SomeFunction()
{
try
{
}
catch(UserTriedToCheatException)
{
throw;
}
catch (Exception ex)
{
Log(ex.ToString());
}
}
Though that code works as expected, I am not content with it. That catch-throw looks so terrible.
Do you have "nicer" suggestions?
|
|
|
|
|
Exceptions don't really matter? Hm ...
I don't find your construct too bad but the alternative which expresses your intent (imo) slightly better is:
try {
} catch(Exception ex) {
if(ex is UserTriedToCheatException) throw;
else Log(ex);
}
|
|
|
|
|
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
|
|
|
|