Quantcast
Channel: PHP: exceptions vs errors? - Stack Overflow
Browsing latest articles
Browse All 13 View Live

Answer by Yolo for PHP: exceptions vs errors?

You may add this comment function doSomething(){ /** @noinspection PhpUnhandledExceptionInspection */ throw new Exception();}

View Article



Answer by Jehong Ahn for PHP: exceptions vs errors?

From PHP: Exceptions - Manual:As of PHP 7.1.0, a catch block may specify multiple exceptions using the pipe (|) character. This is useful for when different exceptions from different class hierarchies...

View Article

Answer by Josef Kufner for PHP: exceptions vs errors?

As stated in other answers, setting error handler to exception thrower is the best way to handle errors in PHP. I use a bit simpler setup:set_error_handler(function ($errno, $errstr, $errfile, $errline...

View Article

Answer by Arturo Hernandez for PHP: exceptions vs errors?

The answer deserves talking about the elephant in the roomErrors is the old way of handling an error condition at run-time. Typically the code would make a call to something like set_error_handler...

View Article

Answer by Elliptical view for PHP: exceptions vs errors?

I intend to give you a most unusual discussion of error control.I built a very good error handler into a language years ago, and though some of the names have changed, the principles of error...

View Article


Answer by Lan for PHP: exceptions vs errors?

I think the anwser you're looking for is that; Errors are the standard stuff you're used to, like echoing a $variable that doesnt exist.Exceptions are only from PHP 5 onwards and come when dealing with...

View Article

Answer by N Zhang for PHP: exceptions vs errors?

Once set_error_handler() is defined, error handler is similar to Exception's. See code below:<?php function handleErrors( $e_code ) { echo "error code: " . $e_code . "<br>"; }...

View Article

Answer by evan for PHP: exceptions vs errors?

Re: "but what exactly is the difference between an error and an exception?"There are a lot of good answers about the differences here. I'll just add in something that hasn't yet been talked about -...

View Article


Answer by Kris for PHP: exceptions vs errors?

I usually set_error_handler to a function that takes the error and throws an exception so that whatever happens i'll just have exceptions to deal with. No more @file_get_contents just nice and neat...

View Article


Answer by Alex Weinstein for PHP: exceptions vs errors?

One thing to add here is about handling exceptions and errors. For the purpose of the application developer, both errors and exceptions are "bad things" that you want to record to learn about the...

View Article

Answer by gnarf for PHP: exceptions vs errors?

Exceptions are thrown - they are intended to be caught. Errors are generally unrecoverable. Lets say for instance - you have a block of code that will insert a row into a database. It is possible that...

View Article

Answer by cgp for PHP: exceptions vs errors?

Exceptions are thrown intentionally by code using a throw, errors... not so much. Errors come about as a result of something which isn't handled typically. (IO errors, TCP/IP errors, null reference...

View Article

PHP: exceptions vs errors?

Maybe I'm missing it somewhere in the PHP manual, but what exactly is the difference between an error and an exception? The only difference that I can see is that errors and exceptions are handled...

View Article

Browsing latest articles
Browse All 13 View Live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>