vb.net - Is a return statement necessary for try catch -


i put try/catch block around email sending logic. if email succeeds, gives confirmation message, if fails, gives failure message. visual studio warning me function doesn't return value on code paths. need put return statements in each try , catch blocks? if do, example put return statements of false or null @ end of try , catch, other code preceding return statements still execute?

function sendmail(byval subject string, byval msg string, byval fromaddress string, byval toaddress string)             try                 dim message new mailmessage                 message.from = new mailaddress(fromaddress)                 each s string in toaddress.split(new [char]() {";"c})                     message.to.add(new mailaddress(s))                 next                 message.subject = subject                 message.body = msg                 message.isbodyhtml = false                 dim client new smtpclient                 client.send(message)                 pnlemailsuccess.visible = true             catch ex exception                 pnlemailsuccess.visible = false                 pnlemailerror.visible = true                 lblerrormsg.text = ex.tostring             end try end function 

to answer question, no not need return statement in try/catch. if not returning value don't need write in function. instead of writing in function write in sub statement or sub procedure. here's link learn more sub procedures.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -