[split] show error toast instead of in debug window |
Author: |
Message: |
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. RE: [Release] Fake media 1.60
Just out of interest, how do you make Plus! show a toast with an error code instead of an error in the Debug window? I had a quick look at your code but couldn't see it...
|
|
06-09-2010 04:29 PM |
|
|
SmokingCookie
Senior Member
Posts: 815 Reputation: 15
30 / /
Joined: Jul 2007
|
RE: [Release] Fake media 1.60
What exactly do you mean? (as in: which error message?)
This post was edited on 06-09-2010 at 04:42 PM by SmokingCookie.
|
|
06-09-2010 04:41 PM |
|
|
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. RE: [Release] Fake media 1.60
Like this.
Occurs when opening the settings window for the second time (or fourth, sixth, and so on).
Attachment: Errors.png (39.55 KB)
This file has been downloaded 295 time(s).
This post was edited on 06-09-2010 at 05:21 PM by whiz.
|
|
06-09-2010 05:20 PM |
|
|
SmokingCookie
Senior Member
Posts: 815 Reputation: 15
30 / /
Joined: Jul 2007
|
RE: [Release] Fake media 1.60
Well, it doesn't happen here Could be that I've got a private version.
Although it definitely means I'll have something to do in the first couple of days of the upcoming vacation.
Fyi, that'll be in 4 to 5 weeks
|
|
06-09-2010 05:27 PM |
|
|
CookieRevised
Elite Member
Posts: 15517 Reputation: 173
– / /
Joined: Jul 2003
Status: Away
|
RE: [Release] Fake media 1.60
quote: Originally posted by whiz
Just out of interest, how do you make Plus! show a toast with an error code instead of an error in the Debug window? I had a quick look at your code but couldn't see it...
Afaik there isn't any magic or hidden setting to enable this.
You show the toast and error yourself.
Do this by using the try {} catch( e) {} methods. And in the catch show a toast with the error number (e.number).
So this wont work for all errors though, only the stuff you 'catch'.
This post was edited on 06-10-2010 at 11:26 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
|
|
06-10-2010 11:26 AM |
|
|
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. RE: [Release] Fake media 1.60
I thought about that, but then I'd have to put one into every function...
Can it go across all functions in a file, like this?
js code: try
{
function Test1()
{
// invalid function
foo.bar();
}
function Test2()
{
Test1();
}
}
catch (error)
{
MsgPlus.DisplayToast("Error!", error.description);
}
|
|
06-10-2010 11:30 AM |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
Joined: Apr 2004
|
RE: [Release] Fake media 1.60
The sample code you defined there won't trigger an exception since you're not calling the functions inside your try block, you are just defining them. Due to the nature of JScript's treatment of global objects, it won't check for the existence of foo on declaration, since foo could still be assigned later. Therefore, there's no real use in wrapping function declarations in try-catch blocks.
Perhaps the best way to implement custom exception handling for all your functions, is to wrap the code inside all your event handlers such as OnEvent_Initialize or OnChatWndEvent_Created. js code: // Main event, wrapped in try-catch block
function OnEvent_Initialize() {
try {
DoThis();
DoThat();
} catch(error) {
MsgPlus.DisplayToast("Error!", error.description);
}
}
// Script functions calling each other
function DoThis() {
HelpMeWithThis();
CallingUnknownFunction(); // try-catch in main event catches this
}
function HelpMeWithThis() { ... }
function DoThat() { ... }
As you can see, despite being wrapped in other functions, the exception will still reach the try-catch block in the event handler. These are the starting points of your call stacks, so any exception occurring inside a function called from the event will bubble up in the call stack until it hits the try-catch block in your event handler code.
|
|
06-10-2010 12:47 PM |
|
|
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. RE: [Release] Fake media 1.60
quote: Originally posted by Matti
Perhaps the best way to implement custom exception handling for all your functions, is to wrap the code inside all your event handlers such as OnEvent_Initialize or OnChatWndEvent_Created.
<code>
As you can see, despite being wrapped in other functions, the exception will still reach the try-catch block in the event handler. These are the starting points of your call stacks, so any exception occurring inside a function called from the event will bubble up in the call stack until it hits the try-catch block in your event handler code.
js code: Debugger.Catch = function(Function, Error)
{
Debugger.Trace("/////////////////////////////////////////////////////////////////");
Debugger.Trace("** Error in: " + Function + " **");
Debugger.Trace("Description: " + Error.description + " (" + Error.code + ")");
Debugger.Trace("Error time: " + new Date());
Debugger.Trace("/////////////////////////////////////////////////////////////////");
}
js code: function OnEvent_Initialize(MessengerStart)
{
try
{
Debugger.Call("Initialize", {"MessengerStart" : MessengerStart});
// ...
foo.bar(); // invalid function
}
catch (error)
{
Debugger.Catch("Initialize", error); // line 72
}
}
code: From the Plus! Script Debug...
Error: Object doesn't support this property or method (code: -2146827850)
File: FnInitialization.js. Line: 72.
Function OnEvent_Initialize returned an error. Code: -2147352318
quote: Originally posted by SmokingCookie
Pleaaaaase don't go offtopic, or my thread will be closed
Can someone split it from my first post, please?
|
|
06-10-2010 06:36 PM |
|
|
SmokingCookie
Senior Member
Posts: 815 Reputation: 15
30 / /
Joined: Jul 2007
|
RE: [Release] Fake media 1.60
Just a stupid question: does the Debugger object support the Trace() method?
|
|
06-10-2010 06:41 PM |
|
|
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. RE: [Release] Fake media 1.60
Yes. Here's the full Debugger object:
Spoiler: js code: var Debugger = {};
Debugger.Start = new Date();
Debugger.Data = [];
Debugger.Trace = function(Text)
{
if (Messenger.MyStatus > 1)
{
try
{
if (Registry.Read("Options\\ChkDebug"))
{
Debug.Trace(Text);
Debugger.Data.push(Text);
}
}
catch (error)
{
Debug.Trace(Text);
Debugger.Data.push(Text);
}
}
else
{
Debug.Trace(Text);
Debugger.Data.push(Text);
}
}
Debugger.Call = function(Function, Parameters)
{
var Notif = Function.substr(Function.length - 19, Function.length);
if (Notif !== "MessageNotification" || (Notif === "MessageNotification" && Registry.Read("Options\\ChkDebugNotif")))
{
Debugger.Trace("=================================================================");
Debugger.Trace("** Event called: " + Function + " **");
Debugger.Trace("Call time: " + new Date());
Debugger.Trace("-----------------------------------------------------------------");
var Count = 0;
for (var Parameter in Parameters)
{
Debugger.Trace("|| " + Parameter + ": " + Parameters[Parameter]);
Count++;
}
if (Count === 0)
{
Debugger.Trace("(no attached parameters)");
}
Debugger.Trace("=================================================================");
}
}
Debugger.Catch = function(Function, Error)
{
Debugger.Trace("/////////////////////////////////////////////////////////////////");
Debugger.Trace("** Error in: " + Function + " **");
Debugger.Trace("Description: " + Error.description + " (" + Error.code + ")");
Debugger.Trace("Error time: " + new Date());
Debugger.Trace("/////////////////////////////////////////////////////////////////");
}
Debugger.Save = function(Path)
{
var TextFile = FSO.CreateTextFile(Path, 2);
TextFile.WriteLine("");
TextFile.WriteLine("=================================================================");
TextFile.WriteLine("**************** Interface Writer: Debugging Log ****************");
TextFile.WriteLine("-----------------------------------------------------------------");
TextFile.WriteLine("Start time: " + Debugger.Start);
TextFile.WriteLine("=================================================================");
TextFile.WriteLine("");
for (var X in Debugger.Data)
{
TextFile.WriteLine(Debugger.Data[X]);
}
TextFile.WriteLine("");
TextFile.WriteLine("=================================================================");
TextFile.WriteLine("End time: " + new Date());
TextFile.WriteLine("=================================================================");
TextFile.Close();
}
Edit: it works if the Debugger::Catch function is specified at the start of the initialization function.
js code: function OnEvent_Initialize(MessengerStart)
{
Debugger.Catch = function(Function, Error)
{
Debugger.Trace("/////////////////////////////////////////////////////////////////");
Debugger.Trace("** Error in: " + Function + " **");
Debugger.Trace("Description: " + Error.description + " (" + Error.number + ")");
Debugger.Trace("Error time: " + new Date());
Debugger.Trace("/////////////////////////////////////////////////////////////////");
}
try
{
Debugger.Call("Initialize", {"MessengerStart" : MessengerStart});
// ...
foo.bar(); // invalid function
}
catch (error)
{
Debugger.Catch("Initialize", error);
}
}
code: From the Plus! Script Debug...
/////////////////////////////////////////////////////////////////
** Error in: Initialize **
Description: 'foo' is undefined (-2146823279)
Error time: Thu Jun 10 20:05:41 UTC+0100 2010
/////////////////////////////////////////////////////////////////
This post was edited on 06-10-2010 at 07:09 PM by whiz.
|
|
06-10-2010 06:58 PM |
|
|
Pages: (2):
« First
[ 1 ]
2
»
Last »
|
|