Someone Posted January 19, 2013 Share Posted January 19, 2013 Exceptions are new to me. How do I give the best error reporting in NWE? Been trying around, like in a class I want to give the game owner a tip when an argument has not been sent to a method. I did throw new Exception('detailed message and sample code'); But then I miss out on the good stuff, like what script and line that method was called from. Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted January 19, 2013 Share Posted January 19, 2013 Well script and line should be handled for you by NWE, I think. No? Can you make a screenshot of the result? Quote Link to comment Share on other sites More sharing options...
Someone Posted January 19, 2013 Author Share Posted January 19, 2013 (edited) Here is if letting it crash, because an undefined index is used: Error: Undefined index: elementName HINT: If you are accessing a GET or POST, make sure to use the isset function. Error in F:/xampp/htdocs/nwe/modules/bootstrap/lib.php Line 18 Error in F:\xampp\htdocs\nwe\modules\gradient_usernames\content.php Line 61 Error in F:\xampp\htdocs\nwe\libs\common.php Line 554 Error in F:\xampp\htdocs\nwe\index.php Line 324 And here by checking if empty, and if it is throw exception Error: Un-handled Exception: The option argument elementName is required. Sample: $instance->Element(array( 'elementName' => 'inputText' )); Error in F:/xampp/htdocs/nwe/modules/bootstrap/lib.php Line 19 Error in F:\xampp\htdocs\nwe\libs\common.php Line 554 Error in F:\xampp\htdocs\nwe\index.php Line 324 The first one includes this gem: Error in F:\xampp\htdocs\nwe\modules\gradient_usernames\content.php Line 61 Exception called like this: function Element($options = array() ){ if( empty($options['elementName']) ){ throw new ErrorException("The argument elementName is required. Sample:<br>\$instance->Element(array(<br> 'elementName' => 'inputText' <br>));"); } } EDit 2: Also tried throw new Exception( instead of ErrorException Edited January 19, 2013 by Someone added how the exception is made Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted January 19, 2013 Share Posted January 19, 2013 Well show the same hints is not possible, however I can try to improve the rows / scripts of the stack. I will check. Quote Link to comment Share on other sites More sharing options...
Someone Posted January 19, 2013 Author Share Posted January 19, 2013 Ok, no worries if not. Ill just let it crash, the generated error message explains the error very well itself, just wanted to follow best practice, and though I might be overlooking something in how stuff works. Quote Link to comment Share on other sites More sharing options...
Someone Posted January 20, 2013 Author Share Posted January 20, 2013 While asking non-critical questions.... I used $this->moduleName = basename(__DIR__); For reading a file in the module directory. So it would not be problem for anyone to rename the module dir to something else. This will ofcource fail when the hook cache is used. Is there a ready made variable for getting the module name. 80% sure there is not, and no big deal as people should be able to figure out how to change a path. Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted January 20, 2013 Share Posted January 20, 2013 No there is no variable for the current script run. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.