I have been working on a conversion project for last few days where I need to convert a Java library to C#. At one point I came to java's certain feature called Exceptions Thrown by a Method. Here is a little glimpse of it:
public boolean isRequest() throws NullPointerException
// blocks of code implementing isRequest() method;
For the C# implementation of this code snippet, I searched the web and quite shockingly found that, C# does not support throwing exceptions in the compile time.
Now my question is, how can I implement this code portion in a C# library?
Congratulations! You're no longer a DaniWeb newbie.<br /> <br />
Your DaniWeb account has just been upgraded from newbie status and now you have the ability to take advantage of everything the community has to offer.<br /> <br />
You can now enjoy an advertisement-free DaniWeb by ticking the checkbox to Disable Ads in your profile. You will no longer have to fill out the human verification check when you post. You can also now send unlimited private messages, contribute new code snippets, and tag articles with never-before-used tags.
@tinstaafl, its not about just throwing exception. In Java using this block(Exceptions Thrown by a Method, follow my link if u please) of code u can check for an exception on compilation time. In C# one cannot simply use a try block which will be executed in compile time, that's why I'm saying C# does not provide this feature by default. I need to know how I can implement it manually.
As a programmer, you really should be aware of what code can throw an exception already. Most documentation will tell you and (especially in possible NullReference cases) you should be checking for null before hand.