c# - How to handle an exception without closing application? -
i have try catch
sending email through wpf c# application followed:
try { smtpmail.send(message); } catch (exception err) { throw new customexception("error contacting server.", err); }
however, don't want application stop running/crash if error hit. rather, change error error message textbox
have set within application...or related not crashing application , rather informing user try again later (or if problem persists: contact so-and-so).
edit: expectation: error logged, user sees this,
errormsg.text = "error contacting server. try again later, or if problem persists contact billy bob boo";
how go implementing this?
update: apologies unclear question. needed on how go logging error display friendly error message user...but asked poorly. using comments , answer provided, researched bit more answered own question below. thanks, everyone! :)
why catching exception , throwing again? doesn't seem effective.
you use messagebox...
try { smtpmail.send(message); }catch (exception err) { messagebox.show(err.message, "exception", messageboxbutton.ok, messageboximage.error); }
edit: said don't wantd user know exception. well, leave catch block empty :)
Comments
Post a Comment