php - Nesting multiple try/catches - is there a better approach? -


i'm making signup process ends final script majority of heavy lifting done, after user has made payment. these processes include:

  • updating our sales db several times
  • making external api post
  • downloading, amending , uploading file via sftp
  • sending confirmation emails

essentially there's lot of things potenatially fail individually, of critical , rely on previous 1 working. don't want final method along lines of

try {     $signup->doeverything(); } catch( exception $e ) {     echo "something went wrong" } 

because no use anybody.

i've ended massive nested list of these final processes 11 deep - work, if 1 of processes fails dies correct exception, seeing many nests assume there should better way of handling these processes.. bad practice? there better solutions dealing large amounts of critical processes this?

you should sub-class exception class

i.e.

class exceptionone extends exception {  ...  } 

then can have 1 try/catch block

i.e.

try {     ... i.e. throw appropriate exception according problem  } catch (exceptionone ex) {    ... } catch (exceptiontwo ex) {    ...  }  etc.  catch (exception ex) {    ... catch } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -