[Dancer-users] Masking warnings with eval/try in development mode?

Assaf Gordon gordon at cshl.edu
Mon Oct 15 18:08:20 CEST 2012


Assaf Gordon wrote, On 10/15/2012 11:53 AM:
> Stéphane Wenric wrote, On 10/15/2012 03:04 AM:
>>> On Fri, Oct 12, 2012 at 10:51 PM, Assaf Gordon <gordon at cshl.edu <mailto:gordon at cshl.edu>> wrote:
>>>
>>>     However, in development mode with "warnings: 1", the "do_something" die()s and the dancer application stops with the standard HTTP 500 page with the stack trace.
>>>
>>>     I don't want to turn "warnings" off, but I want to be able to mask this specific warning.
>>>
>> I guess you could always disable warnings locally, before your function call, and re-enable them after.
>> Something like
>>
>>       no warnings;
> 
> Unfortunately this doesn't work.
> 

Follow-up:
locally disabling SIG{__WARN__} did the trick,

eval {
   local $SIG{__WARN__};   
   do_something_that_might_fail();
   $ok = 1;
};

Based on this thread:  http://www.perlmonks.org/?node_id=51097


But perhaps a better way is to update Dancer::Route::execute(), to check if we're inside an "eval" block, and if so - not "take over" and show error 500 ? (the "eval" implies that the programmer is aware of the possible failure and wants to handle it?)



More information about the Dancer-users mailing list