[Solved] throw 'my error' vs throw new Error('error')

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
Which one should I use and why?

Code:
throw 'my error';throw new Error('my error');
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
Errors are handled like this:

SceneManager.onError = function(e) {    console.error(e.message);    console.error(e.filename, e.lineno);    try {        this.stop();        Graphics.printError('Error', e.message);        AudioManager.stopAll();    } catch (e2) {    }};Since that code assumes, that the error is an object and not a simple String, i'm inclined to say that the 2nd approach is correct. However, if both work for you (because the thrown String gets autoboxed), i don't see any real advantage or disadvantage.
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
Some browsers didn't work correctly with the string option. The error object can also hold more information other than the message itself.
 

Victor Sant

Veteran
Veteran
Joined
Mar 17, 2012
Messages
1,694
Reaction score
1,452
First Language
Portuguese
Primarily Uses
Also, they way both messages are shown on the console is different.:

throw new Error('string') shows on the console the sources of the error.



throw "string' just points to SceneManager.onError.

 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
424
Reaction score
171
First Language
Dutch
Primarily Uses
RMMV
So the object clearly wins. Thanks all.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,863
Messages
1,017,053
Members
137,571
Latest member
grr
Top