Can't catch Exception thrown by Carbon

前端 未结 1 1602
清歌不尽
清歌不尽 2021-02-19 00:27

The following code throws an exception that I can\'t catch for whatever reason.

try {
    $this->date = \\Carbon\\Carbon::parse($this->date)->toDateStri         


        
相关标签:
1条回答
  • 2021-02-19 00:47

    Immediately after posing the question, I thought of the answer. Since I saw a lot of posts online about a very similar issue, I figured I'd go ahead and answer this one.

    The issue was namespacing. Carbon was running in a different namespace from my app (obviously) so when I tried to catch (Exception) I was actually trying to catch an exception within my app's namespace. Changing the catch statement to catch (\Exception) resolved it.

    I hope this helps anyone that ends up on this page.

    0 讨论(0)
提交回复
热议问题