Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 660 Vote(s) - 3.42 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Where to catch exceptions in a MVC framework

#1
Everyone talks about how important exception handling is. I have never had the need to handle them until recently:

try {
$pdo = new PDO($dns);
} catch (Exception $e) {
throw new Exception($e);
}

Another more general example would be:

if ($something) {
throw new Exception('Ouch! I can't do that!');
}

After a little online research, I found that many examples/solutions online simply echo them. (

[To see links please register here]

) Some don't have solutions. (

[To see links please register here]

) & (

[To see links please register here]

) And others, I just dont understand. (

[To see links please register here]

)

**Question #1:** Where should I catch exceptions; in the Model or Controller of a **MVC**ish framework?

**Question #2:** What should catching it do? Log it, email it, display 503?
Reply

#2
I am a .net guy and for me best practices for catching exceptions:

- Catch it as late as possible.
- Write a common code to catch exception.
- Catch it at controller level and log it somewhere with complete stack trace (ETW, Log file, DB etc.).
- Redirect user to some good looking error page. Only controller can do this.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through