I'd like to hear your opinions about the appropriate way to deal with
non-critical errors that can occur in user-defined functions. For
example, an application chooses to extend String.prototype with a
format() method similar to sprintf(). Several formats (%d, %f, etc) are
supported, but %z would be invalid. During the parsing of the format
string, the function encounters an invalid format which (most likely)
was caused by a programmer error.
Should it:
- try a best-guess resolution and continue?
- fail silently (returning an empty or partial result)?
- throw an exception? If so, which one (a string, a user-defined object,
one of the built-in Exception objects)?
- display an alert()?
- do something else?
The target clients are modern browsers, and exceptions are available.
At the moment, I'm using a mix of the above; something similar to this
(reduced example):
function warn (msg) {
if (window.console && typeof window.console.error == "function") {
// If the Firebug console is available, display the error, but
// allow the calling function to continue
window.console.error(msg);
} else {
throw new MyCustomException(msg);
}
}
but I'm not happy with it, because the program flow is different
depending on the availability of Firebug. The format() method may want
to signal a non-critical error, but still try to continue. I guess what
I'm looking for is a way to issue warnings without Firebug. I'd rather
not use alert(), because there could be a large number of warnings when
things go wrong.
- Conrad 5 2999
In comp.lang.javascript message <jKqdnapQFYWXKpnUnZ2dneKdnZydnZ2d@supern
ews.com>, Sun, 26 Oct 2008 19:29:30, Conrad Lender <cr******@yahoo.com>
posted:
>I'd like to hear your opinions about the appropriate way to deal with non-critical errors that can occur in user-defined functions.
That must depend on the purpose of the page being displayed.
For an "advertising" page, the code should probably do its best to
continue, while avoiding making false statements to the reader. But one
might have a test mode, maybe set by the contents of a small include
file or by a special input or by editing a var debug=0; statement.
For an "ordering" page, similar but more cautiously.
For an "instructional", "calculating", or "within-business" page, it's
better to enter a diagnostics mode, proceeding with the original task
only so far as is safe.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036)
On Oct 26, 2:29*pm, Conrad Lender <crlen...@yahoo.comwrote:
I'd like to hear your opinions about the appropriate way to deal with
non-critical errors that can occur in user-defined functions. For
example, an application chooses to extend String.prototype with a
format() method similar to sprintf(). Several formats (%d, %f, etc) are
supported, but %z would be invalid. During the parsing of the format
string, the function encounters an invalid format which (most likely)
was caused by a programmer error.
Should it:
- try a best-guess resolution and continue?
No.
>
- fail silently (returning an empty or partial result)?
Not a partial result. Return null if it fails.
>
- throw an exception? If so, which one (a string, a user-defined object,
one of the built-in Exception objects)?
No.
>
- display an alert()?
Of course not.
>
- do something else?
In addition to returning a "falsy" value (other than undefined of
course) to signal a mistake, clearly document the expected syntax for
the argument(s). At that point it is up to the developer to read the
instructions and handle failures in ways that suit their applications
(some might even want to use alerts.)
>
The target clients are modern browsers, and exceptions are available.
At the moment, I'm using a mix of the above; something similar to this
(reduced example):
function warn (msg) {
* *if (window.console && typeof window.console.error == "function") {
* * * // If the Firebug console is available, display the error, but
* * * // allow the calling function to continue
* * * window.console.error(msg);
* *} else {
* * * throw new MyCustomException(msg);
* *}
}
but I'm not happy with it, because the program flow is different
depending on the availability of Firebug. The format() method may want
Yes, that is less than ideal.
to signal a non-critical error, but still try to continue. I guess what
I'm looking for is a way to issue warnings without Firebug. I'd rather
Then you need to create an object that updates the value of a
TEXTAREA. Optionally, it could echo the messages to the browser's
error console (if the feature is available.) Firebug is not needed at
all.
On 2008-10-28 04:14, dm***@cinsoft.net wrote:
>I guess what I'm looking for is a way to issue warnings without Firebug.
Then you need to create an object that updates the value of a
TEXTAREA. Optionally, it could echo the messages to the browser's
error console (if the feature is available.) Firebug is not needed at
all.
That's a good idea. I could try to add support for other error consoles
than Firebug. I think Opera and Safari allow scripts to print messages
to their consoles; IE doesn't; not sure about Mozilla. I'll have to look
that up.
And you're right, warnings should never result in exceptions, only
non-recoverable errors should do that. A textarea may not be available,
and the DOM may not be ready at the point when a warning should be
issued. But I can store the warnings and let them be retrieved later.
That way the page that uses the library can decide how to handle or
display them.
- Conrad
On Oct 29, 12:05*pm, Conrad Lender <crlen...@yahoo.comwrote:
On 2008-10-28 04:14, dm...@cinsoft.net wrote:
I guess what I'm looking for is a way to issue warnings without Firebug.
Then you need to create an object that updates the value of a
TEXTAREA. *Optionally, it could echo the messages to the browser's
error console (if the feature is available.) *Firebug is not needed at
all.
That's a good idea. I could try to add support for other error consoles
than Firebug. I think Opera and Safari allow scripts to print messages
to their consoles; IE doesn't; not sure about Mozilla. I'll have to look
that up.
I believe the old Mozilla browsers have an error console. I know
NN6.2 has one.
>
And you're right, warnings should never result in exceptions, only
non-recoverable errors should do that. A textarea may not be available,
and the DOM may not be ready at the point when a warning should be
issued. But I can store the warnings and let them be retrieved later.
That way the page that uses the library can decide how to handle or
display them.
Yes. That is exactly what I do.
On Oct 29, 9:05 pm, Conrad Lender <crlen...@yahoo.comwrote:
And you're right, warnings should never result in exceptions, only
non-recoverable errors should do that. A textarea may not be available,
and the DOM may not be ready at the point when a warning should be
issued. But I can store the warnings and let them be retrieved later.
That way the page that uses the library can decide how to handle or
display them.
Returning `null' and pushing the error / warning message in the
library's custom error queue which can be retrieved at any point in
time by the developer indeed seems like a good solution.
../sasuke This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ryan N. |
last post by:
Hello,
I saw a brief blurb on this somewhere and am unable to recall where...
In the context of Security, what are some best practices for
handling -storing, locating, retrieving- database OLEDB...
|
by: aaj |
last post by:
Hi all
I have an automated application, that runs in the middle of the night.
If certain 'non system' errors occur (things like malformed files, missing
files etc..), I send an automatic Email...
|
by: Max |
last post by:
Sometimes I get this error when testing web.mail:
The server rejected one or more recipient addresses
The server response was: 473 kjhg@Kjhg.com relaying prohibited. You should
authenticate first...
|
by: James Radke |
last post by:
Hello,
I am looking for guidance on best practices to incorporate effective and complete error handling in an application written in VB.NET. If I have the following function in a class module...
|
by: Stefan Johansson |
last post by:
Hi all
I'am moving from Visual Foxpro and have a question
regarding "best practice" error handling in vb .net.
In VFP I have always used a "central" error handling
object in order to have a...
| |
by: SStory |
last post by:
When I right a class, I am wondering what are the best practices for error
handling?
Do I try..catch and trap the error and if so what do I do with it? Because
most likely the class user will...
|
by: csgraham74 |
last post by:
Hi guys,
Basically i have been developing in dotnet for a couple of years but
ive had a few issues in regards to error handling.
For example - I have a class that i call passing in a stored...
|
by: Bill Fuller |
last post by:
Here is the scenario. We will be writing a web application that will need to
sometimes properly handle sensitive data (salary, ssn, profit, etc.) using
roles. This data will be restricted at a...
|
by: joshfink |
last post by:
Hey guys,
I am writing an application where I want to follow the best practices on error handling.
This is what I have:
I created an enum for various issues that could happen within the...
|
by: Bob Alston |
last post by:
I have an application with about 30 users, most of whom use the
application on laptops that they take with them. The system is split
into FE and BE. The BE on each laptop is a replica. The...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |