uncaughtException don't workink as expected

时间:2017-08-30 20:26:27

标签: javascript node.js

Code Number 1:

$username = json_encode('something@something.com');

curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"username\":" . $username . ",\"send_welcome\":true,\"welcome_message\":\"Test\",\"account_attributes\":{\"email_address\":\"testuser5@so.com\",\"first_name\":\"Snow\",\"last_name\":\"White\",\"middle_initial\":\"A\",\"phone_number\":\"2055551234\",\"address\":\"1 Main St\",\"city\":\"Detroit\",\"state\":\"MI\",\"zip\":\"48220\",\"country\":\"US\"},\"Gender\":\"Male\",\"portals\":[],\"groups\":[],\"identification_card_numbers\":[]}");

Code Number 2:

declare @table table (ID int, StartDate date, EndDate date)
Insert Into @table
(
    ID
    , StartDate
    , EndDate
)
Values
(1,     '2017-01-01',    '2017-02-01'),
(1,     '2017-01-09',    '2017-01-28'),
(1,     '2017-04-01',    '2017-04-30'),
(1,     '2017-04-05',    '2017-05-20'),
(1,     '2017-04-20',    '2017-06-12'),
(2,     '2017-06-02',    '2017-06-20'),
(2,     '2017-06-14',    '2017-07-31'),
(2,     '2017-06-14',    '2017-07-31'),
(2,     '2017-06-19',    '2017-07-31'),
(2,     '2017-06-19',    '2017-07-31')


;with cte as(
select
    t1.ID
    ,t1.StartDate
    ,t1.EndDate
    ,DT = (select min(StartDate) from @table t2  where t2.StartDate > DATEADD(day,30,t1.StartDate))
from
    @table t1),

cte2 as(
select
    ID
    ,StartDate
    ,EndDate
    ,dense_rank() over (order by isnull(DT,(select max(StartDate) from cte))) as Flag
from
    cte)

select 
    ID
    ,StartDate
    ,EndDate
    ,case when Flag % 2 = 0 then 2 else Flag % 2 end as Flag
from cte2

why the code number 1 is working fine but code number 2 not?

1 个答案:

答案 0 :(得分:3)

In Code Number 1 , you're handling the error before it occurs.

In Code Number 2, the Error happens before you handle it, that's the reason it is not working.