You missed the point of his question. He was not wondering why the code would NOT work, he is wondering why the code DOES work. My guess would be he's taking a .NET class and this is an exersize for the student to explain rethrowing expetions. However, the code in question does not REthrow and exception, it merely throws one and catches it. I should resist the temptation to help you cheat, but here goes anyway. The "try" is saying "run the code between the next two braces, and if an exception is thrown during any of it, then "catch" that exception and run the code in the catch block. If no exception occurs, don't run any of the code in the catch block. Your function MyFn() throws an execption if the parms are null, and the catch block in Main will catch it and run the code in the catch block.
Dave Everett
Posts
-
Rethrowing exceptions: -
Can C# exist without dotnet??It is powerful because it DOES depend on the .NET framework, as do C++.NET and VB.NET. Java depends just as greatly on the JRE, the only difference is terminology. VB6 might be just a little more independent, but you could say that it depends on the Windows framework (system DLLs), they just happen to come with the operating system. I can write a program in PowerBuilder 9 and compile it, but I must make sure the user has PBVM90.DLL and LIBJCC.DLL on the path for that executable. And if I want use Datawindows, PBDWE90.DLL. And if I want to use an ODBC database, PBODB90.DLL and PBODB90.INI. (The list goes on...) Those are PowerBuilder's "framework", although they don't call it that. The advantage with C# (and C++ and VB) .NET is that you (the developer) don't have to worry about the framework being on the path, windows handles that for you. The user can install the .NET framework from the web, and you can just give them your EXE file. (Or whatever you developed). Perhaps you are confused about the difference between the .NET framework and Visual Studio .NET? Your users don't have to have Visual Studio, they only need the .NET runtime, which is freely downloadable from Micorsoft.com.
-
Is there an easier way to find things in C#I don't have "Visual Studio Combined Help collection in the Visual Studio program group in your start menu". Maybe that is the real problem here. Is it something I did not install? I have VS 2003 and .Net Framework 1.1. I was relying too much on web searching, and not on searching specific help files on my own computer. I do have "MSDN Library for Visual Studio .NET 2003" on my start menu, but I had not seen that because it is so well hidden. Maybe all my complaining was for nought. I searched it for "openfile" and it took me right to the OpenFileDialog class. I searched for "mouse pointer", "mousepointer" and "mouse cursor", which didn't get me good results, but when I searched for "cursor" it went right to the Cursor and Cursors classes, which may have helped me, though the examples there were stupid. I couldn't find a good search string for the Keys.L thing, but I think if I was on the KeyEventArgs class, I may have been able to figure out the Keys.L thing. You may have opened a whole new world for me here.
-
Is there an easier way to find things in C#To quote you: '...If you're looking for an open file dialog, type "OpenFileDialog"..' Therein lies the crux of the problem. If I had known that it was called "OpenFileDialog" I wouldn't even have needed to search in the first place because autocomplete will tell me all about the methods, attributes, and events for that class. I searched for "openfile", "fileopen", "getfile", getfilename", "getfileopenname" (The function we use in PowerBuilder), "filechoose", "filename", and a hundred other search strings. No reasonable results came back from MSDN online, the WEB in general, or any books except the one I bought. When I wanted to do the mousepointer thing, the first search string I entered was "cursor", but I got back 100 billion useless VB6, foxpro, and C++ answers for how to use database cursors. So I assumed I was on the wrong track and should search for "mouse", "mousepointer", "mouseicon", "pointer", etc. All to no avail. Your idea about perusing the class library's table of contents is not a bad idea for a rainy day, but when I have a specific question about something in C#, there doesn't seem to be a resource available to me. IF MSDN online would let me filter my search PROPERLY, it might end up being the answer, but it's totally useless as it sits now. I was hoping I could find a searchable reference resource (online or book) on C# specifically.
-
Is there an easier way to find things in C#Please tell me there's an easier way. Here are a few examples of my recent pain: It took me a day and a half of searching the Web, MSDN, and 6 books about C# before I found out there was an OpenFilaDialog class for asking the user which file they wanted my app to open. It took me mere seconds to code a KeyDown event on my RichTextBox, and to figure out that I needed to use KeyEventArgs.Control to see if the control key was pressed, but it took several hours of searching to figure out I needed to compare Keys.L to KeyEventArgs.KeyCode to find out if L was pressed. It took me hours of searching to find out that "Cursor.Current=Cursors.WaitCursor;" would change the mousepointer to the hourglass while my program retrieved from the database. I am not stupid, I have been programming for over 25 years, in RPG, COBOL, TOTAL, ADS/O, PowerBuilder, and probably others along the way. My whole department is going to come to me when they have the question: "In .NET, how do I...?", and I don't want to tell them I'll get back to them in a week. I bought "C# for Experienced Programmers" by Deitel because it was the only book I could find that told me about the OpenFileDialog class. It did not help me with the other two situations I had. I just have to beleive there is a better way...