diff --git a/src/file.cc b/src/file.cc index d905c1db25..6528faee61 100644 --- a/src/file.cc +++ b/src/file.cc @@ -26,7 +26,7 @@ using namespace node; #define ATIME_SYMBOL String::NewSymbol("atime") #define MTIME_SYMBOL String::NewSymbol("mtime") #define CTIME_SYMBOL String::NewSymbol("ctime") -#define BAD_ARGUMENTS String::New("Bad argument") +#define BAD_ARGUMENTS Exception::TypeError(String::New("Bad argument")) static int AfterClose (eio_req *req) diff --git a/src/net.cc b/src/net.cc index c92d9d57da..a5466ac114 100644 --- a/src/net.cc +++ b/src/net.cc @@ -145,14 +145,17 @@ Connection::Connect (const Arguments& args) } if (connection->ReadyState() != EVCOM_INITIALIZED) { - return ThrowException(String::New("Socket is not in CLOSED state.")); + Local exception = Exception::Error(String::New("Socket is not in CLOSED state.")); + return ThrowException(exception); } assert(connection->stream_.recvfd < 0); assert(connection->stream_.sendfd < 0); - if (args.Length() == 0) - return ThrowException(String::New("Must specify a port.")); + if (args.Length() == 0) { + Local exception = Exception::TypeError(String::New("First argument must be a port number")); + return ThrowException(exception); + } String::AsciiValue port_sv(args[0]->ToString()); assert(connection->port_ == NULL); @@ -383,7 +386,8 @@ Connection::Send (const Arguments& args) && connection->ReadyState() != EVCOM_CONNECTED_WO ) { - return ThrowException(String::New("Socket is not open for writing")); + Local exception = Exception::Error(String::New("Socket is not open for writing")); + return ThrowException(exception); } // XXX @@ -424,7 +428,10 @@ Connection::Send (const Arguments& args) } connection->Send(buf, len); - } else return ThrowException(String::New("Bad argument")); + } else { + Local exception = Exception::TypeError(String::New("Bad argument")); + return ThrowException(exception); + } return Undefined(); } @@ -598,8 +605,10 @@ Server::Listen (const Arguments& args) HandleScope scope; - if (args.Length() == 0) - return ThrowException(String::New("Must give at least a port as argument.")); + if (args.Length() == 0) { + Local exception = Exception::TypeError(String::New("First argument must be a port number")); + return ThrowException(exception); + } String::AsciiValue port(args[0]->ToString()); @@ -631,8 +640,10 @@ Server::Listen (const Arguments& args) struct addrinfo *address = NULL, *address_list = NULL; int r = getaddrinfo(strlen(host) ? host : NULL, *port, &server_tcp_hints, &address_list); - if (r != 0) - return ThrowException(String::New(strerror(errno))); + if (r != 0) { + Local exception = Exception::Error(String::New(strerror(errno))); + return ThrowException(exception); + } address = AddressDefaultToIPv4(address_list);