c# exception questions -



c# exception questions -

thank helping.

this code doesn't produce expect when divisor 1. base of operations class exceptone doesn't called, hyperlink in exceptone doesn't displayed. missing ?!

console output is:

enter divisor 1 writeline exception 1... writeline exception 2... base of operations ctor2 http : // exc2.com writeline in finally

class programme { static void main(string[] args) { seek { byte y = 0; byte x = 10; console.writeline("enter divisor"); string s = (console.readline()); y = convert.tobyte(s); if (y == 1) throw new exceptone(); console.writeline("result {0}", x / y); ; } grab (system.dividebyzeroexception e) { console.writeline("exception occured {0}...", e.message); } grab (exceptone p) { console.writeline(p.message +"\n"+ p.helplink); } grab (system.exception r) { console.writeline(r.message + "\n" + r.helplink); } { console.writeline("writeline in "); console.readline(); } } } public class exceptone : system.exception { public exceptone() : base("base ctor 1 ") { this.helplink = "http://exc1.com"; console.writeline("writeline exception 1..."); throw new exception2(); } } public class exception2 : system.exception { public exception2() : base("base ctor2 ") { console.writeline("writeline exception 2..."); this.helplink = "http://exc2.com"; } }

you throwing exception in constructor of exceptone exception. exceptone object never created , grab exception not triggered.

edit

it can ok throw exception in constructor. see: http://bytes.com/topic/c-sharp/answers/518251-throwing-exception-constructor , when right constructor throw exception?

c# exception custom-exceptions

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -