2017-04-14 3 views
0

좋아, 아주 혼란 ​​스럽네. 나는 슬림 프레임 워크를 사용하고 있는데 나는 코드를 다음 있습니다 : PHP가 캐치를 건너 뛰고 캐치를 시도하여 직접 마침내 점프합니다.

1 $app->post("/user/login", function (Request $request, Response $response) { 
2 $resp = null; 
3 try { 
4  if (!array_key_exists("password", $request->getParams()) || !array_key_exists("username", $request->getParams())) { 
5   throw new LiberInvalidRequestException("Not all required parameters were passed."); 
6  } 
7  $user = new User($this->db, [ 
8   'username' => $request->getParam('username'), 
9   'password' => $request->getParam('password') 
10  ]); 
11  try { 
12   $resp['logincode'] = $user->login(); 
13   $resp['success'] = true; 
14  } catch (LiberAuthenticationException $exception) { 
15   $resp['success'] = false; 
16   $resp['errormessage'] = $exception->getMessage(); 
17  } 
18 } catch (LiberInvalidRequestException $exception) { 
19  $resp['success'] = false; 
20  $resp['errormessage'] = $exception->getMessage(); 
21 } finally { 
22  return $response->withJson($resp); 
23 } 
24 }); 

I 오른쪽 PARAMS이 경로를 호출

내가는 null 응답을 얻을. 제 생각에는 가능한 모든 방법으로 무언가가 $resp에 할당 되었기 때문에 이것이 불가능합니다. 디버거와 함께이 함수를 실행하면 12 행까지 갈 수 있고 디버거는 finally 블록 (22 행)으로 점프합니다.

어떻게 이런 일이 가능합니까? 실행이 계속되거나 catch 블록으로 가야합니까?

+0

'LiberAuthenticationException' 또는'LiberInvalidRequestException' 이외의 일부 예외가 발생하면 가능합니다 ... 네임 스페이스가 perchance를 발행합니까? – deceze

+0

@deceze 또 다른 예외가 발생했다고 생각하지 않습니다. 나는 실행이 finally 블록으로 점프 할 때 Point가 composer autoloader 내부의 include 문이라는 것을 발견했습니다. Include 문은 Exceptions IIRC를 throw하지 않습니다. – Aaronmacaron

+0

'try '내부의'try '는 혼란에 가중 될뿐입니다. 여러 개의 'catch'블록이 단일 'try'에 대해 어떻게 쓰여질 수 있는지에 대한 [this] (http://stackoverflow.com/q/8439581/2298301)의 게시물을 참조하십시오. –

답변

0

좋아 문제 해결 방법을 찾았습니다. @deceze가 말했듯이 catch 블록이 잡히지 않은 예외가 발생했습니다. 내가 PHP7.1 포함 문을 사용하므로 예외를 throw 할 수 있습니다. 그것이 예외가 처음에 던져진 이유입니다.

관련 문제