Laravel5 using a try catch instance to explain

Source: Internet
Author: User
Tags try catch
This article mainly describes the Laravel5 use try catch knowledge, the need for friends can refer to the following

Using the following code in LARAVEL5 does not catch the exception

try{Var_dump ($val);} catch (Exception $e) {var_dump ($e); Echo $e->getmessage ();}

Laravel 5 times the controller is forced to be placed under a sub-namespace so that the Exception class under the root namespace cannot be called directly. The controller of the Laravel 4 is directly available under the name space. After PHP 5.3 All classes are defaulted to the namespace, and if not declared, the default is under the top-level namespace.

So to use the syntax of the try catch, either the code uses use \exception at the very beginning, or catch (\exception $e). So the right way to use it is

try{Var_dump ($val);} catch (\exception $e) {var_dump ($e); <br><br>echo $e->getmessage (); <br>}

Ps:laravel 5 Try Catch problem: unable to detect Exception

In a recent project, try Catch was attempted, and it was found to have been unsuccessful

try{Var_dump ($val);} catch (Exception $e) {var_dump ($e);}

In PHP, this code should print the value of $e. However, in Laravel 5, it is not. This is because Laravel 5 enforces the PSR Standard and must use the correct namespace.

So to use the syntax of the try catch, either the code uses use \exception at the very beginning, or catch (\exception $e). So the right way to use it is

try{Var_dump ($val);} catch (\exception $e) {var_dump ($e);}

Summarize

The above is a small part of the Laravel5 to introduce you to the use of Try catch instance of the detailed, I hope that we have some help, if you have any questions please give me a message, small series will promptly reply to you. Thank you very much for the support of PHP Chinese network!

Articles you may be interested in:

A detailed explanation of the responsive interface provided in Laravel 5.5 for response requests

PHP operation Zip in the case of the uncompressed package to display the picture in the package related explanation

PHP implementation of the check-in function of the method Example analysis de detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.