]> git.decadent.org.uk Git - videolink.git/blob - xpcom_support.cpp
Release versions 1.2.11 and 1.2.11-1
[videolink.git] / xpcom_support.cpp
1 // Copyright 2005 Ben Hutchings <ben@decadent.org.uk>.
2 // See the file "COPYING" for licence details.
3
4 #include <cstdio>
5 #include <cassert>
6 #include <memory>
7 #include <stdexcept>
8
9 #include "xpcom_support.hpp"
10
11 namespace xpcom_support
12 {
13     void throw_exception(nsresult error)
14     {
15         assert(NS_ERROR_GET_SEVERITY(error) == NS_ERROR_SEVERITY_ERROR);
16
17         // TODO: look up error message
18         char message[30];
19         std::sprintf(message, "XPCOM error %08x", error);
20
21         switch (error)
22         {
23         case NS_ERROR_OUT_OF_MEMORY:
24             throw std::bad_alloc();
25
26         case NS_ERROR_NOT_INITIALIZED:
27         case NS_ERROR_ALREADY_INITIALIZED:
28         case NS_ERROR_INVALID_POINTER:
29         case NS_ERROR_ILLEGAL_VALUE:
30         case NS_BASE_STREAM_CLOSED:
31         case NS_BASE_STREAM_ILLEGAL_ARGS:
32             assert(!"internal error detected by XPCOM function");
33             throw std::logic_error(message);
34
35         default:
36             throw std::runtime_error(message);
37         }
38     }
39 }