File: xpcom_support.cpp

package info (click to toggle)
videolink 1.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 368 kB
  • ctags: 502
  • sloc: cpp: 3,210; ansic: 880; makefile: 121
file content (38 lines) | stat: -rw-r--r-- 867 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2005 Ben Hutchings <ben@decadent.org.uk>.
// See the file "COPYING" for licence details.

#include <cassert>
#include <memory>
#include <stdexcept>

#include "xpcom_support.hpp"

namespace xpcom_support
{
    void throw_exception(nsresult error)
    {
	assert(NS_ERROR_GET_SEVERITY(error) == NS_ERROR_SEVERITY_ERROR);

	// TODO: look up error message
	char message[30];
	std::sprintf(message, "XPCOM error %08x", error);

	switch (error)
	{
	case NS_ERROR_OUT_OF_MEMORY:
	    throw std::bad_alloc();

	case NS_ERROR_NOT_INITIALIZED:
	case NS_ERROR_ALREADY_INITIALIZED:
	case NS_ERROR_INVALID_POINTER:
	case NS_ERROR_ILLEGAL_VALUE:
	case NS_BASE_STREAM_CLOSED:
	case NS_BASE_STREAM_ILLEGAL_ARGS:
	    assert(!"internal error detected by XPCOM function");
	    throw std::logic_error(message);

	default:
	    throw std::runtime_error(message);
	}
    }
}