Lançado Adianti Framework 7.6!
Clique aqui para saber mais
throw new Exception(_t('Permission denied')); fora do Try Pessoal, na aplicação changeman - StatusFormList, tem throw new Exception(_t('Permission denied')); fora do Try e funciona perfeitamente, estou tentando usar este mesmo form em outro app, está dando um erro como mostra o anexo. Desde já muito obrigado....
AR
throw new Exception(_t('Permission denied')); fora do Try  
Fechado
Pessoal, na aplicação changeman - StatusFormList, tem throw new Exception(_t('Permission denied')); fora do Try e funciona perfeitamente, estou tentando usar este mesmo form em outro app, está dando um erro como mostra o anexo. Desde já muito obrigado.

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (5)


NR

Adriano, você definiu essa mensagem de email já cadastrado? O throw new Exception funciona pois a classe do framework responsável por executar os controls tem um try antes de chamá-las.
AR

Olá Nataniel, muito grato.

Olhe esse código do do app changeman do Pablo.

Repara que ele usa " throw new Exception(_t('Not logged'));" fora do try e funciona perfeitamente.

  1. <?php
  2. /**
  3.  * StatusFormList Registration
  4.  * @author  <your name here>
  5.  */
  6. class StatusFormList extends TStandardFormList
  7. {
  8.     protected $form// form
  9.     protected $datagrid// datagrid
  10.     protected $pageNavigation;
  11.     
  12.     /**
  13.      * Class constructor
  14.      * Creates the page and the registration form
  15.      */
  16.     function __construct()
  17.     {
  18.         parent::__construct();
  19.         
  20.         // security check
  21.         if (TSession::getValue('logged') !== TRUE)
  22.         {
  23.             throw new Exception(_t('Not logged'));
  24.         }
  25.         
  26.         // security check
  27.         TTransaction::open('changeman');
  28.         if (Member::newFromLogin(TSession::getValue('login'))-> role_mnemonic !== 'ADMINISTRATOR')
  29.         {
  30.             throw new Exception(_t('Permission denied'));
  31.         }
  32.         TTransaction::close();
  33.         
  34.         // defines the database
  35.         parent::setDatabase('changeman');
  36.         
  37.         // defines the active record
  38.         parent::setActiveRecord('Status');
  39.         
  40.         // creates the form
  41.         $this->form = new TQuickForm('form_Status');
  42.         $this->form->class 'tform';
  43.         $this->form->setFormTitle(_t('Status'));
  44.         
  45.         $options = array('Y'=>_t('Yes'), 'N'=>_t('No'));
  46.         
  47.         // create the form fields
  48.         $id           = new TEntry('id');
  49.         $description  = new TEntry('description');
  50.         $final_state  = new TRadioGroup('final_state');
  51.         $color        = new TColor('color');
  52.         
  53.         $id->setEditable(FALSE);
  54.         $final_state->addItems($options);
  55.         $final_state->setLayout('horizontal');
  56.         
  57.         // define the sizes
  58.         $this->form->addQuickField('ID'$id,  100);
  59.         $this->form->addQuickField(_t('Description').': '$description,  200);
  60.         $this->form->addQuickField(_t('Final state').': '$final_state,  200);
  61.         $this->form->addQuickField(_t('Color').': ',       $color,  100);
  62.         // define the form action
  63.         $this->form->addQuickAction(_t('Save'), new TAction(array($this'onSave')), 'fa:floppy-o');
  64.         $this->form->addQuickAction(_t('New'), new TAction(array($this'onEdit')), 'fa:plus-square green');
  65.         
  66.         // creates a DataGrid
  67.         $this->datagrid = new TQuickGrid;
  68.         $this->datagrid->width '100%';
  69.         $this->datagrid->setHeight(320);
  70.         
  71.         // creates the datagrid columns
  72.         $this->datagrid->addQuickColumn('ID''id''left'NULL, new TAction(array($this'onReload')), array('order''id'));
  73.         $this->datagrid->addQuickColumn(_t('Description'), 'description''left'NULL, new TAction(array($this'onReload')), array('order''description'));
  74.         $this->datagrid->addQuickColumn(_t('Final state'), 'final_state''left'NULL, new TAction(array($this'onReload')), array('order''final_state'));
  75.         $this->datagrid->addQuickColumn(_t('Color'), 'color''left'NULL);
  76.         
  77.         // add the actions to the datagrid
  78.         $this->datagrid->addQuickAction(_t('Edit'), new TDataGridAction(array($this'onEdit')), 'id''fa:pencil-square-o blue fa-lg');
  79.         $this->datagrid->addQuickAction(_t('Delete'), new TDataGridAction(array($this'onDelete')), 'id''fa:trash-o red fa-lg');
  80.         
  81.         // create the datagrid model
  82.         $this->datagrid->createModel();
  83.         
  84.         // creates the page navigation
  85.         $this->pageNavigation = new TPageNavigation;
  86.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  87.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  88.         
  89.         // creates the page structure using a vbox
  90.         $container = new TVBox;
  91.         $container->style 'width: 100%';
  92.         $container->add($this->form);
  93.         $container->add($this->datagrid);
  94.         $container->add($this->pageNavigation);
  95.         
  96.         // add the container inside the page
  97.         parent::add($container);
  98.     }
  99. }
  100. ?>
</your>
NR

Adriano, o throw funciona porque o código do framework que executa os controls que criamos é o seguinte:
  1. <?php
  2.           try
  3.                 {
  4.                     $page = new $class($_GET);
  5.                     ob_start();
  6.                     $page->show$_GET );
  7.                     $content ob_get_contents();
  8.                     ob_end_clean();
  9.                 }
  10.                 catch(Exception $e)
  11.                 {
  12.                     ob_start();
  13.                     ....
  14. ?>

Onde $page seria o control executado. Pode ver que há um try antes de executá-lo.
No erro que você anexou o throw também está sendo executado. Essa mensagem de email cadastrado é algum IF que você criou?
AR

  1. <?php
  2. /**
  3.  * StatusFormList Registration
  4.  * @author  <your name here>
  5.  */
  6. class StatusFormList extends TStandardFormList
  7. {
  8.     protected $form// form
  9.     protected $datagrid// datagrid
  10.     protected $pageNavigation;
  11.     
  12.     /**
  13.      * Class constructor
  14.      * Creates the page and the registration form
  15.      */
  16.     function __construct()
  17.     {
  18.         parent::__construct();
  19.         
  20.         // security check
  21.        
  22.         if (TSession::getValue('logged') !== TRUE)
  23.         {
  24.             throw new Exception(_t('Not logged'));
  25.         }
  26. ?>


Nataniel, a mensagem do email foi só um teste que fiz, o meu problema está exatamente na linha 24 " throw new Exception(_t('Not logged'));" se coloco o try, funciona, exibi a mensagem mas não para a execução, a tela é aberta. Será que o problema não é porque estou trabalhando em cima do app Blog back-end que baixei do Adianti ?</your>
NR

Pode ser sim, tente colocar um try/catch no index.php, aquele que fica fora da pasta admin.