c# - "Method must have a return type" and "return must not be followed by an object expression" -


im adding method public static class

    public static logmessage(exception ex)     {         trace.writeline(ex.tostring());         return ex;      } 

when this, message says "method must have return type"

and in return message says "since 'util.logmessage(system.exception)' returns void, return keyword must not followed object expression"

how correct this?

you need change declaration return exception:

public static exception logmessage(exception ex) {     trace.writeline(ex.tostring());     return ex;  } 

note that, depending on usage, might make sense allow generic method:

public static t logmessage<t>(t ex) t : exception {     trace.writeline(ex.tostring());     return ex;  } 

this allow use resulting exception in typed manner.

alternatively, not return exception, since logging shouldn't need return exception in case:

public static void logmessage(exception ex) {     trace.writeline(ex.tostring()); } 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

node.js - Node - Passport Auth - Authed Post Route hangs on form submission -

Does Firefox offer AppleScript support to get URL of windows? -