Replaced exception with runtime_error

This commit is contained in:
Robert 2021-01-21 15:48:31 +01:00
parent a9bbbbb7a3
commit aef5818474
5 changed files with 18 additions and 7 deletions

View file

@ -69,7 +69,7 @@ int main(int argc, char** argv)
{
shader = oglu::MakeShader("shaders/vertexShader.vert", "shaders/fragmentShader.frag");
}
catch (const std::exception& e)
catch (const std::runtime_error& e)
{
std::cerr << e.what() << std::endl;
return -1;

View file

@ -10,6 +10,8 @@
#define CORE_HPP
#include <memory>
#include <stdexcept>
#include <string>
#include <glad/glad.h>
#ifdef OGLU_WIN32

View file

@ -9,7 +9,7 @@ namespace oglu
{
if (!gladLoadGLLoader(proc))
{
throw std::exception("Failed to initialize GLAD");
throw std::runtime_error("Failed to initialize GLAD");
}
}

View file

@ -38,8 +38,10 @@ namespace oglu
if (!success)
{
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
std::string err = ("Failed to compile shader " + std::string(vertexShaderFile) + "\n" + infoLog);
delete source;
throw std::exception(std::string("Failed to compile shader " + std::string(vertexShaderFile) + "\n" + infoLog).c_str());
delete infoLog;
throw std::runtime_error(err);
}
delete source;
@ -54,8 +56,10 @@ namespace oglu
if (!success)
{
glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog);
std::string err = ("Failed to compile shader " + std::string(fragmentShaderFile) + "\n" + infoLog);
delete source;
throw std::exception(std::string("Failed to compile shader " + std::string(fragmentShaderFile) + "\n" + infoLog).c_str());
delete infoLog;
throw std::runtime_error(err);
}
delete source;
@ -69,7 +73,9 @@ namespace oglu
if (!success)
{
glGetProgramInfoLog(program, 512, NULL, infoLog);
throw std::exception(std::string("Failed to link program.\n" + std::string(infoLog)).c_str());
std::string err = ("Failed to link program.\n" + std::string(infoLog));
delete infoLog;
throw std::runtime_error(err);
}
// Dispose of shader objects
@ -443,9 +449,10 @@ namespace oglu
if (!file.good())
{
file.close();
throw std::exception(std::string("Failed to open shader file: " + std::string(filename)).c_str());
throw std::runtime_error(std::string("Failed to open shader file: " + std::string(filename)));
}
// TODO: This is just horrendous
std::string str((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
(*buffer) = (char*)malloc(str.size() + 1);
memcpy(*buffer, str.c_str(), str.size());

View file

@ -2,6 +2,7 @@
#define STB_IMAGE_IMPLEMENTATION
#include <stb/stb_image.h>
#include <exception>
namespace oglu
{
@ -27,7 +28,8 @@ namespace oglu
stbi_uc* data = stbi_load(filename, &width, &height, &nrChannels, 0);
if (data == nullptr)
{
throw stbi_failure_reason();
std::string err = std::string(stbi_failure_reason());
throw std::runtime_error(err);
}
glGenTextures(1, &texture);