c# - ThrowException does not exists in the current context -
doing practice in vs2010.
working try/catch/finally , getting following message:
throw exception not exists in current context. missing using statement use throwexcpetion?
using system; using system.collections.generic; using system.linq; using system.text; class program { static string[] etypes = { "none", "simple", "index", "nested index" }; static void main(string[] args) { foreach (string etype in etypes) { try { console.writeline("main() try"); console.writeline("throwing: \"{0}\") called.",etype); throwexception(etype); console.writeline("main() try continuing"); } catch (system.indexoutofrangeexception e) { console.writeline("main system.indexoutofrange catch", e.message); } { console.writeline("main finally"); } console.writeline(); } console.readkey(); } }
you don't have method named throwexception
defined.
if you're trying raise exception, that's not how it's done. you'd do:
throw new sometypeofexception(etype);
given testing, suspect want:
throw new indexoutofrangeexception(etype);
for details, see throw (c# reference).
Comments
Post a Comment