Jump to content
MakeWebGames

Throwing exceptions


Someone

Recommended Posts

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.

Link to comment
Share on other sites

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 by Someone
added how the exception is made
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...