c# - Compiler Requiring Return Value - Not Noticing Unconditional Exception in Called Method -


why c# compiler not smart enough in following scenario?

    void throwex() {         throw new exception();     }      int test() {         throwex();     } 

...test()': not code paths return value

edit: in practice, want extract exception throwing logic separate method because i'm tired typing stuff throw new faultexception<mycustomfault>(new mycustomfault(), "cannot validate input");

it doesn't between methods; not least, method in different assembly , change without rebuilds, or virtual, extern, abstract or partial - confusing spot small number of cases.

you have throwex return "int", , then:

return throwex(); 

which make compiler happy. or use generics:

static t throwex<t>() {...} ... return throwex<int>(); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -