JavaScript Errors Properties & Throwing Exceptions

Quick bit of information on JavaScript errors and throwing errors. (This post uses error and exception as synonyms… not sure what the correct term is in JavaScript)

I was trying to figure out how to get details from an exception thrown in JavaScript and it seems the structure is like this:

  message : “the error message”,
  fileName : “file:///c:/User/me/Desktop/Stuff.js”,
  lineNumber : 57,
  stack : “bunch of stuff here”

(Used json2.js to stringify the error message as Firebug didn’t seem to be showing it… ?)

When you throw your own exceptions you can of course throw anything including a string like this:

throw “This is a string”;

… and when you analyse what you caught it will be a simple string with that value.

try {
    throw "This is a string";
} catch(error) {

The result will be an alert box with the value "This is a string" displayed.

Just found out here that you can do this:

throw new Error(reason);


Storing the NewSequentialID() after Inserting using the Output Clause

A little while ago i wrote this post about returning a NewSequentialID() after inserting a row… Sometimes though you want to be able to do something with that ID within the stored procedure that you are in the scope of…

You can use the output clause to insert certain columns in the inserted table into a temporary table. For example:

The table we are working with…

CREATE TABLE dbo.junk (
      id uniqueidentifier NOT NULL
        DEFAULT newsequentialid()
    , name varchar(100)

CREATE TABLE dbo.junk_history (
      id uniqueidentifier NOT NULL
    , name varchar(100)
    , date datetime DEFAULT getutcdate()

The first table is the table we are inserting into, the second table we want to have filled with the newly inserted values including the id column…

The Stored procedure we have is as follows:

CREATE PROCEDURE dbo.junk_insert
    @name nvarchar(100)
    INSERT INTO dbo.junk (name)
        OUTPUT, INTO dbo.junk_history (id, name)
        SELECT @name

In the insert statement I’m getting the id and name from the row inserted and inserting that into the junk_history table… You can insert the data into a temporary table variable or an actual table.

DECLARE	@return_value int

EXEC	@return_value = [dbo].[junk_insert]
		@name = N'Jimbo Jumbalock'

SELECT	'Return Value' = @return_value


SELECT * FROM dbo.junk
SELECT * FROM dbo.junk_history

The above script calls the sproc and shows you the contents of both tables…

Note: that this was a very quickly put together script to get an example working, so please ignore any weirdness 🙂


Satellite Assemblies – Example in ASP.NET MVC

We were trying to create satellite assemblies for globalization and figured it out in an MVC application…

first time using YouTube… it’s not very clear, but hopefully it helps! … hopefully when this one has finished processing it will be clearer than it is now… as i said. noob at the (you)tube!

Steps are basically:

  1. Add the globalization attribute in the Web.config file
  2. Add a folder for the resx files.  (we don’t want it in App_GlobalData as it won’t be compiled into the current assembly, but a seperate one!)
  3. Create your resx file and contents
  4. Ensure the resx is set to public.
  5. Copy the resx
  6. Create translation (say fr for french)
  7. Create the view to show the contents
  8. Test in both languages

So it’s very simple: Create the resx files, ensure they are public (not 100% whether this is needed, not tested yet!) set the globalization attribute in web.config and change your browser language to test!

Creating a Custom Controller Factory

Quick notes about replacing the current controller factory in ASP.NET MVC

How to Create the Custom Controller Factory

  1. Create a class that inherits from DefaultControllerFactory (see this)
  2. Set the controller factory in application start (see this)

That’s should be about it 🙂

Why would you implement a custom controller factory? (Thoughts for me relating specifically to IoC)

  1. You can configure which type of controller you want, so you can configure the IoC container to load a new class that is in a dll that you chuck in the bin directory.
  2. You can inject the dependencies (like repositories) into the constructor automatically

Other interesting tidbits.