|
Etienne_123 wrote: To prevent my system from crashing when an error does occur
Most often that does not make sense at all.
An exception indicates something went wrong, you can not just ignore it, you should:
1) probably log it
2) act on it (if nothing else, throw it again, so a higher level of the code can act on it).
3) consider informing the user.
And you should only catch the exceptions you can handle in a meaningful way, hence catch them as specific as possible.
Examples:
- when writing to a file, if it fails (error in path, disk full, whatever IOException) you can't ignore that, since then your output would be uncertain; here you must inform the user, unless you have a retry that succeeds.
- when parsing user input, a parse exception has to be reported to the user so he can re-enter data.
The rare exception to the rule is e.g. where you have a retry loop, then all exceptions except for the one in the last retry iteration can be left unhandled and unreported (I suggest to include a comment as to why a catch block is empty then); the exception in the last retry iteration has to be handled though, since that is the exit result of the retry loop.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
I think you need to study exceptions: what they are for and what action you should take when you catch one.
|
|
|
|
|
"On Error Resume Next", and it should be taken out and shot.
I are Troll
|
|
|
|
|
That one belongs exclusive to VB language
|
|
|
|
|
That exact statement, yes, that's confined to Basic, but the pattern can be found in all languages.
I are Troll
|
|
|
|
|
I use parameterless catches on occasion, such as:
try
{
Utilities.DoSQLNonQuery(cmd);
}
catch (Exception) { }
Which is part of my fault logging system. If I can't log a fault, I can't use the exception, but I don't want to lose the user data either.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
"Rumour has it that if you play Microsoft CDs backwards you will hear Satanic messages.Worse still, is that if you play them forwards they will install Windows"
|
|
|
|
|
that is all right, as long as you leave the comment there.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Yes, you can. But the whole point of catching exceptions is to identify an 'exceptional' situation in your code and handle it properly. Having empty catch blocks is worser than not handling exceptions in your code. As a temporary measure, you can atleast log the error and show a message to the user that something wrong has happened.
|
|
|
|
|
Why would you ask us this instead of just trying it ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Christian Graus wrote: Why would you ask us this instead of just trying it ?
Come on Christian, you know the answer as well as the rest of us.
|
|
|
|
|
I did try it and it worked. I was merely making sure.
Why would you reply to a message when you don't aleast try and give an answer? This is the second time you've replied like this to one of my questions. I've said it before and I'll say it again, these forums aren't JUST for experts.
I didn't say I'm not going to handle my exceptions, I just wanted to know whether an empty and parameterless catch will work fine for the time being, as I still need to establish what my user wants to have done when an exception occurs.
|
|
|
|
|
Etienne_123 wrote: I still need to establish what my user wants to have done when an exception occurs.
This is not the way to look at it. If an exception occurs then it indicates a fault in your program, so you need to discover what the fault is and whether the program should continue. There are very few occasions when you should allow the program to continue, as your program, and thus your data/files/security may now be compromised. From this point on anything can happen.
|
|
|
|
|
Etienne_123 wrote: these forums aren't JUST for experts
correct.
everyone is welcome with some eagerness to learn, which includes reading documentation, using Google, experimenting a bit, and asking questions when nothing else helps or some advice is required.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
I'm trying to send 8-bits of output data in C# from my netbook via a USB to Parallel cable. I already have inpout32.dll and thought I could use the integer output address 888 but this doesnt seem to be working?
Can anyone help me with which address I should be using or have code which can send data via a USB to Parallel cable?
Thanks for any help
|
|
|
|
|
Hi I am not sure whether this is your problem,
There is a general problem with USB to parallel. I know for sure that many times USB to parallel does not work and "true" parallel port is required.
T o answer that, Is there another program or application that can do the same thing via the same port and succeed ?
|
|
|
|
|
Don't know about the parallel cable bit, but it may be worth checking out #USBLib[^]. I understand it is good for handling USB communication.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
Dear Coders,
I building a windows application using C#.I build a MDI.MDI has menu.i need when i press like F1(function keys) a specific form will open.This way i want to use F1...F12.Which event and how i do that.
Any suggestion is appreciated.Thanks in Advance.
Shafik
|
|
|
|
|
Clue: ShortcutKeys
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
thank you very much for ur reply.
i using this way but its not working.would u help me:
if(e.KeyCode.ToString()"F1")
{
frmAllCheckInformation objfrmAllCheckInformation=new frmAllCheckInformation();
objfrmAllCheckInformation.ShowDialog();
}
|
|
|
|
|
Use google, or bing, and look for ShortcutKeys for crisake! In the designer, menu command, property ShortcutKeys set it.
JOB DONE. Stop faffing about.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Try with this :
if (e.KeyCode == Keys.F1)
DoSomething();
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
thank u very much.let me check
|
|
|
|
|
Dear Abhijit,
Which MDI's event i will use?I use KeyDown event and i wrote:
if(e.KeyCode==Keys.F1)
{
frmAllCheckInformation objfrmAllCheckInformation=new frmAllCheckInformation();
objfrmAllCheckInformation.ShowDialog();
}
Form is opened only one time.When i close and again press F1 the form is not coming.
would u help me...
|
|
|
|
|
You need to use ProcessKeyMessage
Check It[^]
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|